AXiS2 - Problem in returning the String value. < and > are getting converted to < and >

眉间皱痕 提交于 2019-12-11 11:59:35

问题


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:

&lt;?xml version='1.0' encoding='UTF-8'?&gt;&lt;Element&gt;&lt;InnerElement&gt;ElementValue&lt;/InnerElement&gt;&lt;/&lt;Element&gt;

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? Suggestions are highly welcome.


回答1:


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




回答2:


Probably in WSDL you have xsd:string, so must converts special chars '<', '>' because this is only string. Change wsdl document to ex. xsd:any.



来源:https://stackoverflow.com/questions/7015781/axis2-problem-in-returning-the-string-value-and-are-getting-converted-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!