無法連接到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();
請幫助!
我評論過這部分,仍然無法正常工作 – user1860403