0

我试图了解如何在 Android 上使用 ksoap。我已经执行了这个 ksoap 请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:namespace">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:"method name">
        <urn:mode>"value"</urn:mode>
      </urn:method name>
   </soapenv:Body>
</soapenv:Envelope>

通过 AndroidHttpClient 在 HttpPost 的实体部分中。我尝试用 ksoap 做类似的事情:

 SoapObject root = new SoapObject(NAMESPACE, "method name");
    PropertyInfo pr = new PropertyInfo();
    mode.setName("mode");
    mode.setValue("value");
    root.addProperty(pr);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(root/*request*/);

    Log.d(TAG, envelope.toString());

    HttpTransportSE transport = new HttpTransportSE(url);
    try {
        transport.call(NAMESPACE.concat("/").concat("method name"), envelope);
        Object obj = (Entity) envelope.getResponse();

,但我有一个例外

SoapFault - faultcode: 'SOAP-ENV:Server' faultstring: 'Processing Failure' faultactor: 'null' detail: org.kxml2.kdom.Node@44f7cab0

你能给我一个这个简单请求的例子来了解它是如何工作的吗?

4

2 回答 2

2

解决方案:

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.implicitTypes = true;

    SoapObject root = new SoapObject(NAMESPACE, "method name");
    PropertyInfo mode = new PropertyInfo();
    mode.setNamespace(NAMESPACE);
    mode.setName("mode");
    mode.setValue("value");
    mode.setType(String.class);
    root.addProperty (mode);
   //root.addProperty("mode", "value");
    envelope.setOutputSoapObject(root/*request*/);

    Log.d(TAG, envelope.toString());

    HttpTransportSE transport = new HttpTransportSE(url);
    transport.debug = true;
    try {
        transport.call(NAMESPACE.concat("/").concat("Method of server"), envelope);
        Log.d(Qube.TAG, transport.requestDump);
        Log.d(Qube.TAG, transport.responseDump);

*如果您想避免 xml 中的类型,订单很重要

于 2012-08-17T09:47:07.087 回答
0

您还可以尝试在线生成器工具,该工具可以生成连接到您的 WS 所需的所有类。我最近使用了http://easywsdl.com,我的工作就像一个魅力。

于 2014-04-03T18:38:17.443 回答