马上,这是我的 Soap 调用实现,减去了不相关的部分。
public class MySoapClient implements AbstractSoapClient
{
private String NAMESPACE = "http://www.examples.com/wsdl/MyService/";
private String METHOD_NAME = "getPersonDetails";
private String SOAP_ACTION = "http://www.examples.com/getPersonDetails/";
String URL = "http://192.168.0.10:8088/mockMyServiceBinding?WSDL";
public Object process() throws Exception
{
SoapSerializationEnvelope envelope = generateEnvelope();
return responseObject = makeCall(envelope);
}
private SoapSerializationEnvelope generateEnvelope()
{
// dont set a namespace for the requestobject, otherwise ksoap adds implicit namespaces onto request elements
SoapObject requestObject = new SoapObject("", METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = true;
requestObject.addProperty("name", "Dave");
envelope.setOutputSoapObject(requestObject);
return envelope;
}
private Object makeCall(SoapSerializationEnvelope envelope)
{
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
return envelope.bodyIn;
}
catch (Exception e)
{
e.printStackTrace();
return e;
}
}
}
我认为问题在于SoapObject requestObject = new SoapObject("", METHOD_NAME);
部分。
如果我使用SoapObject requestObject = new SoapObject("", METHOD_NAME);
Then 我在 bodyOut 得到这个:
<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/>
<v:Body>
<getPersonDetails xmlns="" id="o0" c:root="1">
<name>Dave</name>
</getPersonDetails>
</v:Body>
</v:Envelope>
如果我使用SoapObject requestObject = new SoapObject(NAMESPACE, METHOD_NAME);
Then 我在 bodyOut 得到这个:
<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/>
<v:Body>
<n0:getPersonDetails id="o0" c:root="1" xmlns:n0="http://www.examples.com/wsdl/MyService/">
<name i:type="d:string">Dave</name>
</n0:getPersonDetails>
</v:Body>
</v:Envelope>
但是..SoapUI 只接受以下作为有效的 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/>
<v:Body>
<getPersonDetails>
<name>Dave</name>
</getPersonDetails>
</v:Body>
</v:Envelope>
由于某种原因,它不喜欢该xmlns="http://www.examples.com/getPersonDetails/" id="o0" c:root="1"
部分,但我找不到删除它的方法,请帮助!
那么如何才能完全删除 xmlns 声明呢?创建 SoapObject 并将命名空间设置为“”感觉“脏”