2

我已经使用 ksoap2 成功访问了 Web 服务,但我坚持使用数据协定调用 Web 服务方法。

SoapUI 中的 webservice 请求如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"         
xmlns:tem="http://tempuri.org/"   
xmlns:pat="http://schemas.datacontract.org/2004/07/Patient_Service.App_Code.Common">
<soapenv:Header/>
<soapenv:Body>
  <tem:PatientLookups>
     <tem:oPatientDetails>
        <pat:ID>?</pat:ID>
        <pat:Name>?</pat:Name>
        <pat:Age>?</pat:Age>
        <pat:Address>?</pat:Address>
      </tem:oPatientDetails>
   </tem:PatientLookups>
 </soapenv:Body>

参数 ID、姓名、年龄和地址具有不同的命名空间

这是我用来创建请求的代码:

request=new SoapObject(NAMESPACE,"PatientLookups");
SoapObject sub_element=new SoapObject(NAMESPACE, "oPatientDetails");


    for(Map.Entry<String,String> entry: properties.entrySet())
        {
            PropertyInfo pi=new PropertyInfo();
            pi.setNamespace(entityNameSpace);
            pi.setName(entry.getKey());
            pi.setValue(entry.getValue());

            sub_element.addProperty(pi);

        }
        request.addSoapObject(sub_element);

但我在 logcat 中得到了这个异常:

 SoapFault - faultcode: 'a:DeserializationFailed' faultstring: 'The formatter threw an 
 exception while trying to deserialize the message: There was an error while trying to  
 deserialize parameter http://tempuri.org/:oPatientDetails. The 
 InnerException message was 'Error in line 1 position 411. Element   
 'http://tempuri.org/:oPatientDetails' contains data from a type that 
 maps to the name 'http://tempuri.org/:oPatientDetails'. The deserializer 
 has no knowledge of any type that maps to this name. Consider using a 
 DataContractResolver or add the type corresponding to 'oPatientDetails' 
to the list of known types - for example, by using the KnownTypeAttribute attribute or 
by adding it to the list of known types passed to DataContractSerializer.'.  Please see 
InnerException for more details.' faultactor: 'null' detail: null
at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:141)
at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
at org.ksoap2.transport.Transport.parseResponse(Transport.java:100)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:214)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:96)

如何使用 ksoap 创建这个肥皂请求?

4

0 回答 0