从Web服务(axis2)响应中删除xmlns标记

时间:2010-10-28 18:45:01

标签: rest axis2

我使用axis2部署了webserivce。服务类上的方法返回一个字符串。

  

public String getXML(){return   “你好...”; }

并且服务配置如下

<operation name="getXML">
            <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out"
                class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
        </operation>

当我从浏览器(RESTful)调用此服务时,我得到这样的响应

<ns:getXMLResponse xmlns:ns="http://service.drugservice.xyz.com"><ns:return>&lt;response>Hello...&lt;/response></ns:return></ns:getXMLResponse>

我不希望响应字符串周围有xml:ns。我该怎么做?我希望看到响应为

<reponse>Hello...</response>

1 个答案:

答案 0 :(得分:0)

您必须为此使用axis2客户端API。像这样的东西

RPCServiceClient serviceClient = null;

            try {
                serviceClient = new RPCServiceClient();
            } catch (AxisFault e) {
                throw e;
            }

            try {
                EndpointReference targetEPR = new EndpointReference("http://localhost/ws/services/drugService");

                // Authorizing access to the url
                QName action = new QName("http://service.drugservice.xyz.com", "getPricingImagesData");

                Options options = serviceClient.getOptions();
                options.setTo(targetEPR);
                Object obj[] = new Object[] {"3885"};
                OMElement responseObject = serviceClient.invokeBlocking(action,obj);
                String response = responseObject.getFirstElement().getText();

                System.out.println(response);
            } catch (AxisFault e) {
                throw e;
            } finally {
                try {
                    serviceClient.cleanup();
                } catch (AxisFault e) {
                    // do nothing
                }
                try {
                    serviceClient.cleanupTransport();
                } catch (AxisFault e) {
                    // do nothing
                }
            }