2011-06-21 35 views
-1

我創建.NET Web服務方法authenticateuser並需要從的Android應用調用它。我如何在不使用第三方工具的情況下做到這一點?如何通過Android電子呼叫的Webmethods無需使用第三方工具

+0

你能更具體嗎?您是否想要將數據發佈到Web服務並讀回結果? – Genzume

+0

你不需要任何第三方工具。 Android具有可用於解析的SAX和DOM API。 – Sujit

+0

是否要通過POST或GET方法調用方法? – Shah

回答

1

如果你想調用.NET Web服務,並使用POST方法,然後按照下面:

DefaultHttpClient httpclient = getClient(); 

    HttpPost httppost = new HttpPost("complete address"); 

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);//number should be the amount of parameters 

    nameValuePairs.add(new BasicNameValuePair("param_name", "param_value")); 
    nameValuePairs.add(new BasicNameValuePair("param_name", "param_value")); 

    try { 
     httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
     HttpResponse response = httpclient.execute(httppost); 
     HttpEntity ht = response.getEntity(); 

     BasicResponseHandler myHandler = new BasicResponseHandler(); 
       String endResult = ""; 

      endResult = myHandler.handleResponse(response); 

      System.out.println("endResuilt*** = "+endResult); 

      dataStream = endResult; 
     }catch(Exception e){ 
      //Catch the Exception 
     } 

希望這有助於!

相關問題