Search code examples
web-servicesapache-axiscontent-typewebservice-client

Issue with setting the content type for http request header with axis2


I have a webservice client code which accesses a service (Axis2 based). I tried changing the content type in the request header using the following code.

ServiceClient serviceClient = stub._getServiceClient();
Options options = serviceClient.getOptions();
options.setProperty(HTTPConstants.CHUNKED, "true");
options.setProperty(Constants.Configuration.ENABLE_HTTP_CONTENT_NEGOTIATION,"true");
options.setProperty(Constants.Configuration.MESSAGE_TYPE,"text/xml");

But the above code was not working for the content type text/xml .But It worked when I used the content type application/xml .I was not able to set the content type as text/xml.

Can anybody give me a solution for this?


Solution

  • Your client may be using the wrong SOAP version to format its request. text/xml is the SOAP 1.1 content type. application/soap+xml is the content type for SOAP 1.2.

    This page illustrates how to change the SOAP version.

    serviceClient.getOptions().setSoapVersionURI(
                  org.apache.axiom.soap.SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
    

    will set the SOAP version to 1.1, for example.