我是 android 新手,我想调用 wcf 网络服务。我找到了 ksoap2 库并声明应用我找到的示例。应用程序失败并显示以下错误消息:java.net.SocketTimeoutException:连接超时。我在manafist文件上设置了用户权限,如下所示:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
我还从模拟器设置应用程序-> 无线和网络-> 移动网络-> 接入点名称中添加了代理、端口、用户名和密码。我还在运行配置中添加了以下行到其他模拟器命令行选项:
-dns-server ns15.unitechost.in
但它仍然没有工作,任何帮助将不胜感激。
更新
使用以下命令启动 AVD 时,我已从命令行配置代理设置:
emulator -avd <avd_name> [-<option> [<value>]] ... [-<qemu args>]
现在我得到了以下异常:
org.xmlpull.v1.XmlPullParserException: unexpected type (position:TEXT HTTP/1.1 500 Int...@11:1 in java.io.InputStreamReader@40531d48)
我已经看到使用 ksoap2 使用 .asmx Web 服务的示例,这也可以在 .svc Web 服务上完成吗?我正在使用随附的代码,如果示例如下所示,我是从其中获得的:
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class Main extends Activity {
/** Called when the activity is first created. */
private static final String SOAP_ACTION = "http://tempuri.org/Istock/getCountry";
private static final String OPERATION_NAME = "getCountry";
private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ADDRESS = "http://127.0.0.1:8080/Service1.svc";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
setContentView(textView);
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
OPERATION_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
try
{
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
textView.setText(response.toString());
System.out.println(response.toString());
}
catch (Exception exception)
{
String exceptionStr=exception.toString();
textView.setText(exceptionStr);
System.out.println(exceptionStr);
Log.i("TAG",exceptionStr);
}
}
}
谢谢,