AXiS2 - Problem in returning the String value. < and > are getting converted to < and >
I have written a simple web service which takes string as an argument and returns a String as output.
The service is something like this :
@WebService(name = "MyWebService", serviceName = "MyWebService", portName = "WS")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public class MyWebService {
@WebMethod(action = "inputString")
@WebResult(name = "resultString")
public String serviceMethod(
@WebParam(mode = WebParam.Mode.IN, name = "inputString") String inputString) {
resultString ="<?xml version='1.0' encoding='UTF-8'?><Element><InnerElement>ElementValue</InnerElement></<Element>"
System.out.println(resultString);
return resultString;
}
}
At the client Side I am getting:
<?xml version='1.0' encoding='UTF-8'?><Element><InnerElement>ElementValue</InnerElement></<Element>
This input is used in the third party parser which tries to find < or > and my application breaks.
Has any one come across this issue? What might be the issue and work around? Suggestion开发者_如何学运维s are highly welcome.
I'll admit I don't spend a lot of time researching it, but the last time I looked there was no good defined way to return an XML document as part of another XML document, which is basically what you are trying to do here. From what I remember reading, even in CDATA sections there could be problems. What you are seeing is the standard encoding for those characters in XML. If I'm remembering right its the XML header that messes up the CDATA sections, but again, its been a long time since I looked at it.
HTH
Probably in WSDL you have xsd:string, so must converts special chars '<', '>' because this is only string. Change wsdl document to ex. xsd:any.
精彩评论