2011-03-14 90 views
1

这是我的SOAP Web服务:Android的SOAP解析

POST /thehlb/mobile/mobileservice.asmx HTTP/1.1 
Host: projects.spinxweb.net 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "http://tempuri.org/CheckLogin" 

<?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> 
    <CheckLogin xmlns="http://tempuri.org/"> 
     <UserName>string</UserName> 
     <Password>string</Password> 
     <PhoneType>string</PhoneType> 
     <MoblieUniqueNo>string</MoblieUniqueNo> 
    </CheckLogin> 
    </soap:Body> 
</soap:Envelope> 

这是我的代码..

public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     //CALL the web service method with the two parameters vname and nname 
     SoapObject request = new SoapObject(NAMESPACE, METHOS_NAME); 
     request.addProperty("UserName","[email protected]"); 
     request.addProperty("Password", "123"); 
     request.addProperty("PhoneType", "Android"); 
     request.addProperty("MoblieUniqueNo", "123456"); 

     SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelop.setOutputSoapObject(request); 
     AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL); 
     androidHttpTransport.debug = true; 

     try 
     { 
      androidHttpTransport.call(SOAP_ACTION, envelop); 

      // Get the SAOP Envelope back and the extract the body 

      SoapObject resultsRequestSOAP = (SoapObject) envelop.getResponse(); 
      System.out.println("Responce :"+resultsRequestSOAP.toString()); 
      Vector vector = (Vector) resultsRequestSOAP.getProperty("CheckLogin"); 

      //Count of the arrays beneath starting from 0 
      SoapObject test = (SoapObject) vector.get(0); 

      //Get the attributes in the array 
      String uName = (String) test.getProperty("UserName"); 
      uName = uName + " " + (String)test.getProperty("Password"); 

      System.out.println("uname "+uName); 


      //Just show it in a text area field called lblStatus 
       TextView tv = (TextView) findViewById(R.id.textview); 
       tv.setText(uName.toString()); 

       System.out.println("user name :"+tv); 

     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
      System.out.println("Error :"+e); 
     } 

    } //end onCreate method 

我得到一个错误解析它。有没有人有办法解决吗? Plz帮助我。

+0

什么是错误? – Adinia 2011-03-14 13:38:45

+0

什么是错误? – longhairedsi 2011-03-14 13:41:17

+0

SoapFault - faultcode:'System.Web.Services.Protocols.SoapException:服务器无法处理请求。 ---> System.NullReferenceException:未将对象引用设置为对象的实例。 – dev 2011-03-14 13:50:17

回答

0

您可以尝试使用soapui或其他工具来查看服务是否正常工作。然后,如果服务正在运行,请检查您放入的soap信封是否与由SoapUI创建的信封相同(除了标记名称预修复)。如果有差异检查。