Using JSON as the message format for a WCF REST service has some advantages
if you are building a backend service for a purely browser based application.
For instance, JSON is natively supported in all of the major web browsers.
I had to build a REST client using Axis2 that uses the JSON message format.
The blog post Enabling JSON in Apache Axis2 explains the conventions that are used to map XML to JSON and how to configure axis2.xml so that your client application can use the XML/JSON mapping convention of your choice.
I chose the mapped namespace convention which can be configured by adding the two lines to your axis2.xml
If you choose the mapped namespace convention you may get an exception that says “JSON mapped namespaces are not supported in Axis2”. If you see the above Axis2 exception then you need to patch jettison.
The ServiceClient (org.apache.axis2.client.ServiceClient) object can be used to make REST API calls in Axis2.
The ServiceClient can be configured using the Options (org.apache.axis2.client.Options) object.
For a REST style service invocation you need the following options,
Options options = new Options();
//reuse HTTP clients
The httpClient object is created via the MultiThreadedHttpConnectionManager. This is needed for managing the HTTP connections if your client is used in a multithreaded application. See the post “Improving Axis2 Client HTTP Transport Performance”
Finally, you have to engage the addressing module and set the ServiceClient options
client = new ServiceClient();
The ServiceClient sendReceive call takes an OMElement which I created using custom XML serialization on the message objects.
Make sure you cleanup the http connections via the httpconnectionManager used to create the httpClient. Again. see the post “Improving Axis2 Client HTTP Transport Performance” on how to do this correctly.
The sendReceive call can be made non-blocking if you are looking for further improvements in performance.
The response returned by the sendReceive call is an OMElement again and can be de-serialized using custom XML de-serialization on your message objects.
If you are looking for pure SOAP interoperability between WCF .NET SOAP client and an Axis2 service be sure to chek out my other post Axis2 and WCF .Net Interoperability (Interop)