2012-04-28 96 views
0

當我的web服務是這樣的時候,如何調用web srvice使用soap ..我需要填寫cus詳細信息我該如何做到這一點..可以任何人指導我在這在android中發送嵌套的請求

<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; 
+0

你會莫名其妙地送''< /''>代替''<' '>我 – zapl 2012-04-28 12:30:53

+0

我給出完整的代碼..我沒有提任何東西如</>然後它是如何hpnd – Dinu 2012-04-28 12:40:41

+0

某些東西不起作用,同時構建或發送XML'' - >'< c usDetails >'。但我不知道SoapObject是如何工作的。 – zapl 2012-04-28 12:44:55

回答

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);