我将我的Android代码与Webservice
连接以检索数据。而且我总是得到:
SoapFault - faultcode: 'a:InternalServiceFault' faultstring: 'Error in deserializing body of request message for operation
'insertAuditData'. OperationFormatter encountered an invalid Message
body. Expected to find node type 'Element' with name 'insertAuditData'
and namespace 'http://tempuri.org/'. Found node type 'Element' with
name 'insertAuditData' and namespace 'http://tempuri.org'' faultactor:
'null' detail: org.kxml2.kdom.Node@44f6a4e8
我的代码是
private static final String SOAP_ACTION3 = "http://tempuri.org/IService/GetSpecificAuditData";
private static final String SOAP_ACTION2 = "http://tempuri.org/IService/insertAuditData" ;
private static final String SOAP_ACTION = "http://tempuri.org/IService/GetAllAuditData";
private static final String METHOD_NAME = "GetAllAuditData";
private static final String METHOD_NAME2 = "insertAuditData";
private static final String METHOD_NAME3 = "GetSpecificAuditData";
private static final String NAMESPACE = "http://tempuri.org//";
private static final String URL = "http://70.33.215.18/PortalService.svc?wsdl";
private boolean isResultVector = false;
public Audit CallGetALL()
{
final String sGetSingle = METHOD_NAME;
// Create the outgoing message
final SoapObject requestObject = new SoapObject(NAMESPACE, sGetSingle);
// Create soap envelop .use version 1.1 of soap
final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
// add the outgoing object as the request
envelope.setOutputSoapObject(requestObject);
envelope.addMapping(NAMESPACE,Audit.Audit_CLASS.getSimpleName(),Audit.Audit_CLASS);
// call and Parse Result.
final Object response = this.call(SOAP_ACTION, envelope);
Audit result = null;
if (response != null)
{
result = new Audit((SoapObject) response);
}
return result;
}
protected Object call(String soapAction,SoapSerializationEnvelope envelope)
{
Object result = null;
final HttpTransportSE transportSE = new HttpTransportSE(URL);
transportSE.debug = false;
// call and Parse Result.
try
{
transportSE.call(soapAction, envelope);
if (!isResultVector)
{
result = envelope.getResponse();
} else
{
result = envelope.bodyIn;
}
} catch (final IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final XmlPullParserException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
答案 0 :(得分:4)
有一点很突出,那就是你没有在requestObject上设置任何属性。
GetSpecificAuditData的序列化SOAP XML可能看起来像这样......
<k:GetSpecificAuditData xmlns:k="http://tempuri.org//"></k:GetSpecificAuditData>
Web服务可能希望GetSpecificAuditData具有与之关联的一些数据。也许是记录ID?这只是我的猜测,因为我不知道Web服务规范是什么样的。
查看SoapObject的addProperty方法。
另外,仔细检查您的命名空间。最后的斜杠也可能导致服务出现问题。
如果你有兴趣,我写了一篇关于ksoap2-android的教程,可以在...找到...
http://www.shanekirk.com/2011/11/speaking-soap-with-android/