2012-12-14 45 views
0

無法連接到web服務有了Android 它不接取web服務代碼 我試圖讓線程,然後我的代碼運行有 我測試從我的手機web服務鏈接,其可達無法連接到web服務藉助Android

這裏的代碼.NET和Android的: -

Webservice的代碼.NET:強大的文本

Imports System.Web 
Imports System.Web.Services 
Imports System.Web.Services.Protocols 

<WebService(Namespace:="http://tempuri.org/")> _ 
Public Class Service 
    Inherits System.Web.Services.WebService 

    <WebMethod()> _ 
    Public Function HelloWorld() As Integer 
     Return 0 
    End Function 

End Class 

這裏是代碼

public class MainActivity extends Activity implements OnClickListener { 

    ImageButton btn1; 
    ImageButton Save; 
    private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld"; 
    private static final String MethodName = "HelloWorld"; 
    private static final String NameSpace = "http://tempuri.org/"; 
    private static final String URL = "http://172.20.10.2/WebSite9/Service.asmx"; 
@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     final Thread webser = new Thread() { 

      public void run() { 

       try { 
        // String project = titles.get(position - 1); 

       //  CallWebService(); 
       SoapObject request = new SoapObject(NameSpace, MethodName);   
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
        envelope.dotNet=true; 

        // request.addProperty("TextToDisplay", "This is coming from android"); 
       envelope.setOutputSoapObject(request); 

        androidHttpTransport.call(SOAP_ACTION, envelope); 

        SoapObject result = (SoapObject)envelope.getResponse(); 
       // Toast.makeText(MainActivity.this,result.toString(), Toast.LENGTH_LONG).show(); 

       } catch (Exception e) { 

        Log.e("tag", e.getMessage()); 

       } 


      } 

     }; 
     webser.start(); 

請幫助!

回答

1

你的代碼似乎是確定

請確保: -

1-使用kso​​ap2-Android的2.5.2.jar
2-轉到構建路徑>添加外部JAR並選擇它 3-將ksoap2-android-2.5.2.jar複製並粘貼到libs文件下

重新啓動應用程序並嘗試?

0

把這個代碼:

SoapObject result = (SoapObject)envelope.bodyIn; 

,而不是這個

SoapObject result = (SoapObject)envelope.getResponse(); 

,它會與你正常工作。

+0

我評論過這部分,仍然無法正常工作 – user1860403