我正在尝试连接到我的 asp Web 服务并使用此代码获取响应。它没有给出错误,但它也没有连接到我的网络服务。谁能指出我的错误?谢谢
public class MainActivity extends Activity {
private static final String SOAP_ACTION = "http://tempuri.org/MyFirstWebMethod";
private static final String OPERATION_NAME = "MyFirstWebMethod";
private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ADDRESS = "http://10.0.2.2:1595/test.asmx";
String name = "Test";
String last = "Me";
String result;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((Button) findViewById(R.id.btngo)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
request.addProperty("name", name);
request.addProperty("last", last);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(SOAP_ADDRESS);
try {
ht.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
result = response.getProperty(1).toString();
}
catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(getBaseContext(), ""+result, Toast.LENGTH_LONG).show();
}
});
}
}
原木猫是这样说的
11-08 13:15:00.344: I/Choreographer(977): Skipped 58 frames! The application may be doing too much work on its main thread.
11-08 13:15:00.405: W/System.err(977): android.os.NetworkOnMainThreadException
11-08 13:15:00.405: W/System.err(977): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
11-08 13:15:00.413: W/System.err(977): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
11-08 13:15:00.413: W/System.err(977): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
11-08 13:15:00.413: W/System.err(977): at libcore.io.IoBridge.connect(IoBridge.java:112)
11-08 13:15:00.413: W/System.err(977): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
11-08 13:15:00.413: W/System.err(977): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
11-08 13:15:00.413: W/System.err(977): at java.net.Socket.connect(Socket.java:842)
11-08 13:15:00.413: W/System.err(977): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:76)
11-08 13:15:00.413: W/System.err(977): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
11-08 13:15:00.413: W/System.err(977): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:341)
11-08 13:15:00.413: W/System.err(977): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
11-08 13:15:00.413: W/System.err(977): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
11-08 13:15:00.413: W/System.err(977): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
11-08 13:15:00.413: W/System.err(977): at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
11-08 13:15:00.413: W/System.err(977): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
11-08 13:15:00.437: W/System.err(977): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
11-08 13:15:00.437: W/System.err(977): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
11-08 13:15:00.437: W/System.err(977): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:75)
11-08 13:15:00.437: W/System.err(977): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:136)
11-08 13:15:00.437: W/System.err(977): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:90)
11-08 13:15:00.437: W/System.err(977): at com.example.xmlparser.MainActivity$1.onClick(MainActivity.java:39)
11-08 13:15:00.443: W/System.err(977): at android.view.View.performClick(View.java:4084)
11-08 13:15:00.443: W/System.err(977): at android.view.View$PerformClick.run(View.java:16966)
11-08 13:15:00.443: W/System.err(977): at android.os.Handler.handleCallback(Handler.java:615)
11-08 13:15:00.443: W/System.err(977): at android.os.Handler.dispatchMessage(Handler.java:92)
11-08 13:15:00.443: W/System.err(977): at android.os.Looper.loop(Looper.java:137)
11-08 13:15:00.443: W/System.err(977): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-08 13:15:00.443: W/System.err(977): at java.lang.reflect.Method.invokeNative(Native Method)
11-08 13:15:00.453: W/System.err(977): at java.lang.reflect.Method.invoke(Method.java:511)
11-08 13:15:00.453: W/System.err(977): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-08 13:15:00.453: W/System.err(977): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-08 13:15:00.453: W/System.err(977): at dalvik.system.NativeStart.main(Native Method)
11-08 13:15:00.618: I/Choreographer(977): Skipped 49 frames! The application may be doing too much work on its main thread.