Monday, July 7, 2014

How to Send a String Parameter to an Axis2 Web Service

If you have written a web service operation which accept a String parameter, You will not be able to pass a string value directly. The below operation is required a string parameter. Then you need to wrap the text inside the CDATA tag. Other wise it will not read the parameter value.

     public void echo(String request)  {
        System.out.println(request);
    }

If you want to send a simple string , You need to wrap it with CDATA. The the output will be >> "Text Content"

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wso2="http://wso2.org">
   <soapenv:Header />
   <soapenv:Body>
      <wso2:echo>
         <!--Optional:-->
         <wso2:request><![CDATA[Text Content]]></wso2:request>
      </wso2:echo>
   </soapenv:Body>
</soapenv:Envelope>
 
If you want to pass a xml content as a string then you have to use CDATA tag as bellow.
Then the output will be >> "<foo>Test</foo>"
 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wso2="http://wso2.org">
   <soapenv:Header />
   <soapenv:Body>
      <wso2:echo>
         <!--Optional:-->
         <wso2:request><![CDATA[<foo>Test</foo>]]></wso2:request>
      </wso2:echo>
   </soapenv:Body>
</soapenv:Envelope> 

You need CDATA tag always to send the String value to a web service operation if they have String type parameter

No comments:

Post a Comment