XML Validation in REST Services - rest

I am going to develope REST(without any framework like SPRING) services which can accept xml. I am going to create XSD for the input xml format.
Now, when client sends some invalid xml which is not as per schema, how should i validate it? Do i need to write a specific code to validate. Can't it get failed in the client side itself?
Previously we had soap service, so if i try to send soap request which is not as per schema, soapui will throw error. The request even will not come to server i guess.
I hope you understood my question, please clarify.

RESTful clients are free to transmit any content they wish to the server, and even try to negotiate different encoding formats like JSON instead of XML. That's part of the power of REST.
It's up to the server to validate that clients send correctly encoded data in the payload, and return a 400-range status code such as 400 - Bad Request if they do not.
You will need to write all your server validation code yourself unless the REST API framework on the server side provides it for you.

Related

How to handle BizTalk POST while exposing schema as REST service?

I have a BizTalk application where I have exposed schema as a RESTful web service, which calls another REST service. I am able to successfully handle GET, DELETE request.
Is there a way to handle POST request without writing a pipeline component to serialize the POST request to a schema?
Also, the application may have to handle several POST calls, so will it be possible to serve this from one single receive location and then filtering the request on the send port?
Please let me know if any more details are required.
So, here's the thing. You're mixing together some things that technically have nothing to do with each other.
For instance, a Plain Old Xml (POX) service, usually a POST, does not 'expose' a Schema in the way a SOAP service does. It just takes whatever content is POSTed to it.
Following that, serialization/deserialization is also a concept more related to SOAP that POX or REST.
So...
Yes, but what exactly are you doing?
Yes. A plain http endpoint can accept any content type. Once it's over the wire, all the normal BizTalk processing rules apply.

Asp.Net Web API content negotiation

…API/emailMessage/?emailId=test123
I have written the above URL using Web API to get the email in JSON data format(email body, sender, CC, To, etc).
Also, I have the requirement to allow download of email along with attachment for the same URL.
One way to do it is using content negotiation. I can use “MediaTypeHeaderValue("application/octet-stream")” to send the content as downloadable.
Question is….
1. Which parameter in the GET request the user should request for JSON content or download of content? Or what is the correct way of asking the content type from HTTP client?
2. On the server side I can read what content type the user is asking and send the appropriate data just using case statement. Is there anything to be considered on the server side in this scenarios?
Thank you,
Eric
The Accept request header is used to inform the server what media types the client supports. However, do not be concerned about adding a format= parameter to your URI to request a different format. It will not have a negative impact on your application.

Example of a SOAP payload for IDEONE

Has anyone got a sample SOAP payload for the ideone.com service?
I've tried several clients including the Firefox SOA client ( which returns an error from the service), the 360Works java soap client which crashes on reading the wsdl, and the online soapclient.com which returns nothing.
I tried two of the SOAP clients you mentioned, soapclient.com and Firefox SOA, and successfully accessed the service at ideone.com.
First, make sure you are using the API password when trying the service and not the site password.
With soapclient.com, make sure that you're viewing the results as XML. You won't see anything if you choose HTML (one of their options).
With both clients, make sure you don't interpret the status with a key name of "error" as meaning that an error has been returned, if the value of this field is "OK". This indicates success.

Can I send a SOAP message to a web service without using tool kits like gsoap and get the same result, or is it necessary to use gsoap?

I mean that if I know the format of message that I want to send, then can I do it manually by sending the message as a string over HTTP without using gsoap and get the same desired result?
There is no problem doing it manually. It will even work using just telnet, as long as you use the correct headers and message body.
SOAP is an application layer protocol. So, it will make no difference if you use a tool
or just create and connect a Tcp/Ip socket to the web service endpoint. As long as you
put the right xml with the soap envelope, headers and body it will work well.

CXF Jax-RS server service returning only header but no response JSON

I have a very basic Rest Server which returns JSON object. I tested it with Poster Firefox extension and I get both header and response.
But we have a test javascript client, which calls the service and when checked with Firebug, we see there is a header but no response.
To be sure, we tested the client with another JSON server and the client can read both the header and response.
As I mentioned, it is a very basic Apache CXF, Jax-RS service, so we are not sure what could be missing , that prevents from sending response or prevents client from reading response.
Will appreciate any help or input.
thank you
Walker
It wasn't the server it was the client which was not able to read the response properly.