2014-01-17 130 views
0

我正在使用KSOAP2庫調用ASP.NET Web服務。我沒有得到任何錯誤,但我也沒有得到任何答案任何想法來解決這個問題。KSOAP2不返回任何結果

以下是我的代碼。我只是簡單地調用返回字符串的helloworld默認方法。

public class MainActivity extends Activity { 

     private final String NAMESPACE = "http://tempuri.org/"; 
     private final String URL = "http://(ip)/TrialService.asmx"; 
     private final String SOAP_ACTION = "http://tempuri.org/HelloWorld"; 
     private final String METHOD_NAME = "HelloWorld"; 
     TextView t1; 

     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 
      t1 = (TextView) findViewById(R.id.textView1); 

      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
      if (android.os.Build.VERSION.SDK_INT > 9) { 
       StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() 
         .permitAll().build(); 
       StrictMode.setThreadPolicy(policy); 
      } 
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11); 
      envelope.dotNet = true; 
      envelope.setOutputSoapObject(request); 
      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
      try { 
       androidHttpTransport.call(SOAP_ACTION, envelope); 
       String receivedInt = (String) envelope.getResponse(); 
       t1.setText(receivedInt); 
       setContentView(t1); 
      } catch (Exception e) { 
       t1.setText("error"); 
      } 
     } 
    }  

回答

0

首先通過啓用調試,這樣就可以看到你向服務器發送SOAP信封的內容開始,你可以做到這一點通過增加(見註釋部分):

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
androidHttpTransport.debug = true;//ADD THIS 
try { 
    androidHttpTransport.call(SOAP_ACTION, envelope); 
    //ADD THESE 2 
    //Important Outputs to check how the request/Response looks like.. Check them in Logcat to find these outputs 
    System.out.println("requestDump is :"+androidHttpTransport.requestDump);//ADDED 
    System.out.println("responseDump is :"+androidHttpTransport.responseDump);//ADDED 

    String receivedInt = (String) envelope.getResponse(); 
    t1.setText(receivedInt); 
    setContentView(t1); 
} catch (Exception e) { 
     t1.setText("error"); 
} 

現在您可以看到發送到服務器的肥皂信封,請檢查它是否準確。

下一頁(你可以從你的桌面上使用的程序發送像SoapUI.一個信封比較吧):

  • 你必須提供更多信息,以便我們能更好地幫助您:把副本您的相關WSDL部分。

  • 確保您使用的是正確的值:命名空間METHOD_NAME,網址,SOAP_ACTION

  • 如果這是一個測試項目,你可以訪問服務器,你可以把它作爲一個獎金檢查發送請求時服務器上發生了什麼。

更多的參考,可以幫助你看到我的答案在:link1link2link3link4