如何将数据发送到Soap服务?

时间:2017-12-13 08:52:53

标签: java android soap android-ksoap2

Soap service需要以下操作:

<wsdl:operation name="UploadFile">
<soap:operation soapAction="http://abcdotcom/IDocUpload/UploadFile" style="document"/>
<wsdl:input name="FileInfo">
<soap:header message="tns:FileInfo_Headers" part="Name" use="literal"/>
<soap:header message="tns:FileInfo_Headers" part="Length" use="literal"/>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="DownloadRequest">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>

我正在使用ksoap2 library。我无法弄清楚如何将数据发送到服务? 我正在尝试

request.addProperty("FileInfo", "123"); 

但它只是给了我null回复。我期待至少error。请帮忙。

1 个答案:

答案 0 :(得分:3)

android中的示例soap请求(方法:FetchUserDetails)

SoapObject request = new SoapObject("http://tempuri.org/", "FetchUserDetails");
request.addProperty("key", value);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);
        envelope.dotNet = true;
        try {
            HttpTransportSE androidHttpTransport = new HttpTransportSE(ServiceURL);
            androidHttpTransport.call("http://tempuri.org/FetchUserDetails", envelope);
            SoapObject response = (SoapObject) envelope.getResponse();
            int count = response.getPropertyCount();
            if (count > 0) {
             //handel the response
             SoapObject results = (SoapObject) response.getProperty(i);
           }
       }catch (Exception e) {
            Log.e("service", e.getMessage());
      }