KSOAP2 正在向 SOAP 请求添加 id 属性
KSOAP2 is adding id property to SOAP request
我正在使用此代码从我的 Android 应用中使用 SOAP Web 服务:
SoapObject request = new SoapObject(NAMESPACE, METHOD);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
Element headerElements[] = new Element[2];
headerElements[0] = new Element().createElement(HEADER_NAMESPACE,"locale");
headerElements[0].addChild(Node.TEXT,"es_MX");
Element authElement = new Element().createElement(HEADER_NAMESPACE,"authentication");
Element usernameElement = new Element().createElement(HEADER_NAMESPACE,"username");
usernameElement.addChild(Node.TEXT,"myUser");
Element pwdElement = new Element().createElement(HEADER_NAMESPACE,"password");
pwdElement.addChild(Node.TEXT,"pwd");
authElement.addChild(Node.ELEMENT, usernameElement);
authElement.addChild(Node.ELEMENT, pwdElement);
authElement.setPrefix(null, HEADER_NAMESPACE);
headerElements[1] = authElement;
envelope.headerOut = headerElements;
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, envelope);
} catch (IOException | XmlPullParserException e) {
Log.e("myapp",e.getMessage(), e);
}
Log.i("dump request", httpTransport.requestDump);
但是在服务器端我收到这样的错误:
Attribute 'id' is not allowed to appear in element 'n1:listAssignments'
...这是生成的 XML 请求
<v:Envelope
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:d="http://www.w3.org/2001/XMLSchema"
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header>
<n0:locale xmlns:n0="http://mycompany.com/ws/soapheaders">es_MX</n0:locale>
<n1:authentication xmlns:n1="http://mycompany.com/ws/soapheaders">
<n1:username>myUser</n1:username>
<n1:password>pwd</n1:password>
</n1:authentication>
</v:Header>
<v:Body>
<n2:listAssignments id="o0" c:root="1" xmlns:n2="http://example.com/mx/mycompany/ws/webadjuster/WebAdjusterAPI" />
</v:Body>
</v:Envelope>
如您所见,生成的 XML 请求包含 "id" 和 "c:root" 属性。为什么会这样?我怎样才能避免它?
提前致谢
添加此代码
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);"
在此之前:
envelope.implicitTypes = true;
envelope.setAddAdornments(false);
我正在使用此代码从我的 Android 应用中使用 SOAP Web 服务:
SoapObject request = new SoapObject(NAMESPACE, METHOD);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
Element headerElements[] = new Element[2];
headerElements[0] = new Element().createElement(HEADER_NAMESPACE,"locale");
headerElements[0].addChild(Node.TEXT,"es_MX");
Element authElement = new Element().createElement(HEADER_NAMESPACE,"authentication");
Element usernameElement = new Element().createElement(HEADER_NAMESPACE,"username");
usernameElement.addChild(Node.TEXT,"myUser");
Element pwdElement = new Element().createElement(HEADER_NAMESPACE,"password");
pwdElement.addChild(Node.TEXT,"pwd");
authElement.addChild(Node.ELEMENT, usernameElement);
authElement.addChild(Node.ELEMENT, pwdElement);
authElement.setPrefix(null, HEADER_NAMESPACE);
headerElements[1] = authElement;
envelope.headerOut = headerElements;
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, envelope);
} catch (IOException | XmlPullParserException e) {
Log.e("myapp",e.getMessage(), e);
}
Log.i("dump request", httpTransport.requestDump);
但是在服务器端我收到这样的错误:
Attribute 'id' is not allowed to appear in element 'n1:listAssignments'
...这是生成的 XML 请求
<v:Envelope
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:d="http://www.w3.org/2001/XMLSchema"
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header>
<n0:locale xmlns:n0="http://mycompany.com/ws/soapheaders">es_MX</n0:locale>
<n1:authentication xmlns:n1="http://mycompany.com/ws/soapheaders">
<n1:username>myUser</n1:username>
<n1:password>pwd</n1:password>
</n1:authentication>
</v:Header>
<v:Body>
<n2:listAssignments id="o0" c:root="1" xmlns:n2="http://example.com/mx/mycompany/ws/webadjuster/WebAdjusterAPI" />
</v:Body>
</v:Envelope>
如您所见,生成的 XML 请求包含 "id" 和 "c:root" 属性。为什么会这样?我怎样才能避免它?
提前致谢
添加此代码
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);"
在此之前:
envelope.implicitTypes = true;
envelope.setAddAdornments(false);