格式化SOAP响应

时间:2012-01-02 10:14:11

标签: soap format response

我正在尝试创建一个Web服务来生成对ping请求的简单soap响应:

<soap:Envelope>
<soap:Body>
<CustomRS attr="somevalue">
<Success/>
</CustomRS>
</soap:Body>
</soap:Envelope>

相反,我得到了这个回复

<soap:Envelope>
<soap:Body>
<PingResponse>
<CustomRS attr="somevalue">
<Success/>
</CustomRS>
</PingResponse>
</soap:Body>
</soap:Envelope>

“Ping”是我的WebMethod的名称,CustomRS是我的Serializable响应对象。如何摆脱PingResponse元素并将CustomRS作为根元素?

我的实施

@WebService (name = '', serviceName = ''targetNamespace = '')
 @Stateless (mappedName = '')

 public class TestEjb implements Testnterface {
@SOAPBinding(style=Style.DOCUMENT, use=Use.LITERAL, parameterStyle=ParameterStyle.BARE)

@WebResult (name = "CustomRS", targetNamespace = "name space")
@WebMethod (operationName = "CustomRS")
public CustomRS_OutPut Ping( @WebParam (name = "header",Type type,
  @WebParam (name = "parameters", Param param) throws Exception
{

}

1 个答案:

答案 0 :(得分:0)

public SoapObject soap(String METHOD_NAME, String SOAP_ACTION,
            String NAMESPACE, String URL) throws IOException,
            XmlPullParserException {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); // set up
                                                                        // request
        request.addProperty("iTruckId", "1");
        request.addProperty("iLocationId", "1");// variable name, value. I got
                                                // the variable name, from the
                                                // wsdl file!
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11); // put all required data into a soap
                                        // envelope
        envelope.setOutputSoapObject(request); // prepare request
        AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
        httpTransport.debug = true; // this is optional, use it if you don't
                                    // want to use a packet sniffer to check
                                    // what the sent
                                    // message was (httpTransport.requestDump)
        httpTransport.call(SOAP_ACTION, envelope); // send request
        SoapObject result = (SoapObject) envelope.getResponse(); // get response
        return result;
    }
}