无法连接和执行Android Web服务 [英] Not able to connect and execute Android Web services
本文介绍了无法连接和执行Android Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I have created java activity.. like below... But my code doesn't work
package com.web.ws;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.serialization.SoapPrimitive;
import org.xmlpull.v1.XmlPullParserException;
public class WSActivity extends Activity {
/** Called when the activity is first created. */
private static final String SOAP_ACTION = "http://tempuri.org/GetDepCode";
private static final String METHOD_NAME = "GetDepCode";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://localhost:100/Service.asmx";
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView)findViewById(R.id.tv);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("QCode");
pi.setValue("0473");
pi.setType(PropertyInfo.INTEGER_CLASS);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive sp=SoapPrimitive)envelope.getResponse();
tv.setText("Value:"+sp);
}
catch (IOException e) {e.printStackTrace(); }
catch (XmlPullParserException e) {e.printStackTrace();}
}
}
and Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
package="com.web.ws"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minsdkversion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application>
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity>
android:name=".WSActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
推荐答案
您好,
替换以下
Hello,
Replace the following
private static final String URL = "http://localhost:100/Service.asmx";
与
with
private static final String URL = "http://10.0.2.2:100/Service.asmx";
选中此亲爱的 Localhost [
Check this dear Localhost[^]
这篇关于无法连接和执行Android Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文