在android中发送嵌套请求

时间:2012-04-28 12:17:13

标签: java android soap

当我的网络服务是这样时,如何使用肥皂调用网络服务..我需要填写cus详细信息我该怎么做...任何人都可以指导我这个

<registerCustomer xmlns="http://webservices.foodtruck.zsl.com/">
  <cusDetails>
    <FirstName>string</FirstName>
    <LastName>string</LastName>
    <EmailID>string</EmailID>
    <AddLine1>string</AddLine1>
    <AddLine2>string</AddLine2>
    <ZipCode>string</ZipCode>
    <City>string</City>
    <StateCode>string</StateCode>
    <PhoneNumber>string</PhoneNumber>
    <Username>string</Username>
    <Password>string</Password>
    <BrandID>int</BrandID>
    <DiscAgree>int</DiscAgree>
    <Latitude>string</Latitude>
    <Longitude>string</Longitude>
  </cusDetails>
       </registerCustomer>
       </soap:Body>
     </soap:Envelope>

我用来调用服务的代码:     final String METHOD_NAME = ServiceStrings.registerMethod;         final String SOAP_ACTION = ServiceStrings.registerSoapAction;         试试{

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        PropertyInfo pi = new PropertyInfo();

        pi.setName("cusDetails");
        pi.setValue(new SoapObject(NAMESPACE, "cusDetails")
        .addProperty("FirstName", fname)
        .addProperty("LastName", lname)
        .addProperty("EmailID", email)
        .addProperty("AddLine1", add1)
        .addProperty("AddLine2", add2)
        .addProperty("ZipCode", zip)
        .addProperty("City", city)
        .addProperty("StateCode", state)
        .addProperty("PhoneNumber", phoneno)
        .addProperty("Username", email)
        .addProperty("Password", pwd)
        .addProperty("BrandID", 1)
        .addProperty("DiscAgree", 1)
        .addProperty("Latitude", "11.2")
        .addProperty("Longitude", "11.2"));

        request.addProperty(pi);

但是我收到了错误

Server was unable to read request. ---&gt; There is an error in XML document (1, 316). ---&gt; The specified type was not recognized: name='cusDetails', namespace='http://webservices.foodtruck.zsl.com/', at &lt;cusDetails xmlns='http://webservices.foodtruck.zsl.com/'&gt;

1 个答案:

答案 0 :(得分:0)

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        PropertyInfo pi = new PropertyInfo();
        pi.setName("cusDetails");
        pi.setValue(new SoapObject(NAMESPACE, "Customer")
                .addProperty("FirstName", fname)
                .addProperty("LastName", lname)
                .addProperty("EmailID", email)
                .addProperty("AddLine1", add1)
                .addProperty("AddLine2", add2).addProperty("ZipCode", zip)
                .addProperty("City", city).addProperty("StateCode", state)
                .addProperty("PhoneNumber", phoneno)
                .addProperty("Username", email)
                .addProperty("Password", pwd)
                .addProperty("BrandID", brandid)
                .addProperty("DiscAgree", flag)
                .addProperty("Latitude", "11.2")
                .addProperty("Longitude", "11.2"));

        request.addProperty(pi);
        Log.e("req", brandid);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(
                URL);