[英]ksoap2 connection timeout
我正在尝试从android模拟器调用.net Web服务,但出现连接超时异常。
在尝试致电我的WebService之前,我已经成功致电http://www.w3schools.com/webservices/tempconvert.asmx 。
因此,我假设在Android应用程序中.net webService中出现问题。
.net是
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Pros : System.Web.Services.WebService {
[WebMethod]
public List<Product> Get(int pageIndex,int pageSize) {
var efUnitOfWork = new EFUnitOfWork();
var productsRepos = new ProductRepository(new EFRepository<Product>(), efUnitOfWork);
return (List<Product>)productsRepos.GetByPage(pageIndex, pageSize);
}
}
Java是
private static final String METHOD_NAME = "Get";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://10.0.0.2:2807/webservices/webService.asmx";
private static String SOAP_ACTION = NAMESPACE+METHOD_NAME;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("pageIndex", "0");
request.addProperty("pageSize", "10");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result=(SoapObject)envelope.getResponse();
String resultData=result.getProperty(0).toString();
}
catch (Exception e) {
e.printStackTrace();
}
}
我想念什么吗?
您可以尝试增加通话超时,如下所示:
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL, 15000);
您应该尝试如上所述增加超时,但是更重要的是,您必须将调用移入后台线程。 使用AsyncTask。
同样,如评论中所述,在ksoap2-android Wiki中链接了一个博客文章,详细解释了连接内容。 您不能使用localhost或同等的主机,因为它在设备上,但是您的服务在服务器上运行..现在我再次查看代码.. 10.0.0.2最不可能。
在服务器上执行ifconfig / ipconfig并使用该IP地址。 我敢打赌它会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.