gpt4 book ai didi

android - 如何删除 ksoap 中的命名空间声明?

转载 作者:行者123 更新时间:2023-11-29 14:28:45 25 4
gpt4 key购买 nike

马上,这是我的 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); 然后我在 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); 然后我在 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 并将命名空间设置为“”感觉很“脏”

最佳答案

一起玩

envelope.implicitTypes = true;

还有

envelope.setAddAdornments(false);

看看你是否让它做你想做的事。还要记住,最终请求是完全有效的,这将取决于您的服务器是否可以接受它而不是 SoapUI。

关于android - 如何删除 ksoap 中的命名空间声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8949020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com