2011-03-11 80 views

回答

6

Soap消息的解析不包含在Android運行時中,所以它不是非常簡單。您應該使用外部庫。我使用ksoap2

如果你在這裏搜索StackOverflow,你會看到很多關於如何使用它的例子。例如here

1

試試這個代碼

 DefaultHttpClient httpClient=new DefaultHttpClient(); 
    String responseString = null; 
    try 
    { 

    HttpPost httppost = new HttpPost("http://services/?wsdl"); 
    httppost.setHeader("SOAPAction", "urn:getSearch"); 
    httppost.setHeader("Content-Type", "text/xml; charset=utf-8"); 

    String strEnvelope = "SOAP BODY" ; 

    HttpEntity entity = new StringEntity(strEnvelope); 
    httppost.setEntity(entity); 
    ResponseHandler<String> strResponseHandler=new BasicResponseHandler(); 
    responseString = httpClient.execute(httppost, strResponseHandler); 
    Log.d("Search", responseString); 

    } 
    catch (Exception objException) 
    { 
     throw objException ; 

    } 
    finally 
    { 
     httpClient.getConnectionManager().shutdown(); 
    } 
2

也值得一試WSClient++。它生成所有存根和模型對象,並隱藏所有解析和綁定到對象。

我在Android中被迫使用肥皂時使用它。它不是免費的,但會爲你節省大量的時間,而這似乎需要巫術才能讓它工作(這可能會改變我最後一次嘗試1年前)

2

只需完成上面的代碼,包括驗證:

httpClient.getCredentialsProvider().setCredentials(new AuthScope("serverIP", portNo), 
      new UsernamePasswordCredentials(username, password));