我正在用Webservice连接我的Android代码来检索数据。我总是得到这样的结果:
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;
}发布于 2011-11-21 22:56:36
最突出的一点是,您没有在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/
https://stackoverflow.com/questions/8192955
复制相似问题