在Android中获取WCF REST GET请求 [英] Get WCF REST GET request in Android
问题描述
当我使用Andoroid齐射库调用WCF服务时,它将引发TimeOut Exception.这是我的代码.这段代码有什么错误.
When I call to my WCF service using andoroid volley library it throw TimeOut Exception. This is my code. What is the error of this code.
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
String URL = "http://192.168.42.200:10963/DisasterService.svc/type/findDisType";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, URL, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
Toast.makeText(getApplicationContext(),"Ok",Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(),response.toString(),Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),e.toString(),Toast.LENGTH_SHORT).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(),error.toString(),Toast.LENGTH_SHORT).show();
}
});
jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(30000, 1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue.add(jsonObjectRequest);
WCF服务终结点
<service name="DisasterServices.DisasterService" behaviorConfiguration="DisasterServices_Behavior">
<endpoint address="area" binding="webHttpBinding" contract="DisasterServices.IAreaService"></endpoint>
<endpoint address="type" binding="webHttpBinding" contract="DisasterServices.IDisasterTypeService"></endpoint>
<endpoint address="suggestion" binding="webHttpBinding" contract="DisasterServices.ISuggestion"></endpoint>
<endpoint address="user" binding="webHttpBinding" contract="DisasterServices.Iuser"></endpoint>
<endpoint address="alerts" binding="webHttpBinding" contract="DisasterServices.IUserAlerts"></endpoint>
</service>
接口-IDisasterTypeService
方法需要调用-GetAllDisasterType
Interface - IDisasterTypeService
Method need to call - GetAllDisasterType
推荐答案
我找到了解决方案.我向IIS服务器中的applicationhost.config文件添加了一些绑定.
I found the solution for this. I added some binding to applicationhost.config file in IIS server.
<site name="myservice" id="5">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="E:\vs\myservice" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:10963:127.0.0.1" />
<binding protocol="http" bindingInformation="*:8085:127.0.0.1" />
<binding protocol="http" bindingInformation="*:8085:192.168.42.200" />
</bindings>
然后我安装了iis代理并将端口更改为代理
Then I installed iis proxy and change the port to proxy
npm install -g iisexpress-proxy
iisexpress-proxy 10963 to 8085
10963是应用程序运行的端口,而8085是代理端口
10963 is the port which application run and the 8085 is the proxy port
最终我在android应用程序中更改了网址
Final I changed my URL in android application
String URL = "http://192.168.42.200:8085/myservice.svc/test/2";
这篇关于在Android中获取WCF REST GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!