如何在SOAP请求Body中处理多个标记

时间:2012-07-26 10:29:15

标签: android soap android-ksoap2

我在我的应用程序中使用SOAP Webservice。我面临的问题是,SOAP请求体中有一个额外的标记。因为我得到了SOAP Fault错误“SoapFault - faultcode:'soap:Server'faultstring:'Server无法处理请求.-->对象引用没有设置为对象的实例。' faultactor:'null'详细信息:org.kxml2.kdom.Node@40516ce8“。

这是SOAP请求....

POST /appws.asmx HTTP/1.1
Host: www.xxxxxx.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://xxxxxxx.com/saveCustomerProfile"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<saveCustomerProfile xmlns="http://xxxxxx.com/">
  <customerProfile>
    <id>long</id>
    <name>string</name>
    <lastName>string</lastName>
    <phoneNumber>string</phoneNumber>
    <zipCode>string</zipCode>
    <email>string</email>
    <birthday>string</birthday>
    <gender>string</gender>
    <emailExclusiveSavings>boolean</emailExclusiveSavings>
    <textExclusiveSavings>boolean</textExclusiveSavings>
  </customerProfile>
</saveCustomerProfile>
</soap:Body>
</soap:Envelope>

以下是我用来调用此webservice的代码

   SoapObject request = new SoapObject(NAMESPACE, "saveCustomerProfile");
    request.addProperty("id", 0);
            request.addProperty("name","aaaaa");
            request.addProperty("lastName","bbbbbb");
            request.addProperty("phoneNumber", "1234567890");
            request.addProperty("zipCode", "1234");
            request.addProperty("email", "123@gmail.com");
            request.addProperty("birthday", "02/02/2011");
            request.addProperty("gender", "male");


      request.addProperty("emailExclusiveSavings","true");
  request.addProperty("textExclusiveSavings", "false");

      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);

    HttpTransportSE httpTransport = new HttpTransportSE(URL);
            httpTransport.call(SOAP_ACTION, envelope);
            System.out.println("response "+envelope.getResponse());

我发现问题出在哪里。

  <saveCustomerProfile xmlns="http://xxxxxx.com/">
     <customerProfile>

通常在SOAP体内只有一个主标签,这里我有两个和。我不知道如何处理它。我已经检查了一些其他SOAP Web服务,所有正在使用相同的代码。请帮帮我。

1 个答案:

答案 0 :(得分:0)

请参阅此Tutorial ..可以帮助您: