马上,这就是我的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>


BUT..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,则将取决于您的服务器。

10-06 13:48