我是android的新手,我想调用wcf web服务。我找到了ksoap2库,并声明应用我发现的示例。应用失败,出现以下错误消息:java.net.SocketTimeoutException:连接超时。 我已经在manafist文件上设置了用户权限:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
我还从模拟器设置app->添加了代理,端口,用户名和密码。无线和网络 - &gt;移动网络 - &gt;接入点名称。 我还将运行配置中的以下行添加到其他模拟器命令行选项中:
-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);
}
}
}
谢谢,
答案 0 :(得分:0)
连接超时发生在:
类似于连接超时是连接被拒绝,但在这种情况下,目标系统实际上正在发送数据包说“离开,您尝试连接的端口上没有运行服务”
连接超时是网络环境中的预期行为。在移动环境中,甚至更加期望网络连接不可靠。这意味着服务器无法响应一定的秒数。
答案 1 :(得分:0)
您无法使用localhost或127.0.0.1从android访问本地计算机。您需要使用10.0.2.2来访问本地计算机。
实际上我没有让android正确连接到WCF服务......
答案 2 :(得分:0)
虽然这可能有点晚了,但这就是为我解决的问题:
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,60000);
注意第二个参数,即超时值。
我必须承认很难,我不知道这个值的规模,但我认为这是以毫秒计算的。
答案 3 :(得分:0)
添加:
temp->symbol=strdup(str);