使用android消耗WCF服务 [英] Consuming WCF service with android

查看:58
本文介绍了使用android消耗WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的WCF服务应用程序。该服务部署在IP为10.0.0.14的服务器上。当我从桌面Web浏览器和移动浏览器访问URL:http:// 10.0.0.14 / jonts / WCFService.svc`时,我可以ping服务器。



我有一个实现REST的服务接口,如下所示:



命名空间WCF_Connection

{



[ServiceContract]

公共接口IWCFService

{

[OperationContract]

[WebGet(UriTemplate =Test / {msg})]

string sayHello(string msg);

}



}



当我使用WCF服务时,转到`http:// 10.0.0.14 / jonts / WCFService.svc / test / one`我得到了一个没有问题的回复。当我在android中运行以下内容时,我在日志中得到一个http://10.0.0.14 rejected`连接错误。





private void消息()

{

HttpClient httpClient = new DefaultHttpClient();

尝试

{

String url =http://10.0.0.14/jonts/WCFService.svc/test/dasd;



HttpGet method = new HttpGet(新URI(url));

HttpResponse response = httpClient.execute(方法);

Toast.makeText(getApplicationContext(),getResponse(response.getEntity() ),

Toast.LENGTH_LONG)。show();

} catch(IOException e){

Log.e(error, e.getMessage());

} catch(URISyntaxException e){

Log.e(error,e.getMessage());

}

}



我的IIS日志如下:



#Software:Microsoft Internet Information Services 8.0

#Version:1.0

#日期:2014-07-01 08:20:09

#Fields:日期时间s-ip cs-method cs-uri -stem cs-uri-query s-port cs-username c-ip cs(User-Agent)cs(Referer)sc-status sc-substatus sc-win32-status time-taken

2014- 07-01 08:20:09 10.0.0.14 GET /jonts/WCFService.svc - 80 - 10.0.0.1 Mozilla / 5.0 +(Windows + NT + 6.3; + WOW64)+ AppleWebKit / 537.36 +(KHTML,+ like + Gecko )+ Chrome / 35.0.1916.153 + Safari / 537.36 - 200 0 0 885

2014-07-01 08:20:23 10.0.0.14 GET /jonts/WCFService.svc - 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 84

2014-07-01 08:20:23 10.0.0.14 GET /jonts/WCFService.svc disco 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 43

2014-07-01 08:20:23 10.0.0.14 GET /jonts/WCFService.svc wsdl 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+ Client + Protocol + 4.0.30319.34014) - 20 0 0 0 74

2014-07-01 08:20:23 10.0.0.14 GET /jonts/WCFService.svc xsd = xsd0 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 546

2014-07-01 08:20:23 10.0.0.14 GET /jonts/WCFService.svc xsd = xsd1 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 93

2014- 07-01 08:20:24 10.0.0.14 GET /jonts/WCFService.svc - 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014 ) - 200 0 0 99

2014-07-01 08:20:24 10.0.0.14 GET /jonts/WCFService.svc disco 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 46

2014-07-01 08:20:24 10.0.0.14 GET /jonts/WCFService.svc wsdl 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 74

2014-07- 01 08:20:24 10.0.0.14 GET /jonts/WCFService.svc xsd = xsd0 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 46

2014-07-01 08:20:24 10.0.0.14 GET /jonts/WCFService.svc xsd = xsd1 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+ Client + Protocol + 4.0.30319.34014) - 200 0 0 77

2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc - 80 - 10.0.0.1 Mozilla / 4.0+(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 106

2014-07-01 08:20:35 10.0。 0.14 GET /jonts/WCFService.svc disco 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 46

2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc wsdl 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+ Protocol + 4.0.30319.34014) - 200 0 0 73

2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc xsd = xsd0 80 - 10.0.0.1 Mozilla / 4.0+(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 46

2014-07-01 08:20:35 10.0.0.14 GET / jonts / WCFService.svc xsd = xsd1 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 79

2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc - 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 131

2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc disco 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 46

2014-07-01 08:20:35 10.0.0.14 GET / jonts / WCFService.svc wsdl 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 62

2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc xsd = xsd0 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0。 30319.34014) - 200 0 0 50

2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc xsd = xsd1 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 74

2014-07-01 08:21:02 10.0.0.14 GET / jonts / WCFService.svc - 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 102

2014 -07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc disco 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0。 30319.34014) - 200 0 0 39

2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc wsdl 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE +6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 62

2014-07-01 08:21:02 10.0.0.14 GET / jonts / WCFService。 svc xsd = xsd0 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 49

2014 -07-01 08:21: 02 10.0.0.14 GET /jonts/WCFService.svc xsd = xsd1 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 73

2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc - 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS +网络+服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 104

2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc disco 80 - 10.0。 0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 46

2014-07-01 08:21: 02 10.0.0.14 GET /jonts/WCFService.svc wsdl 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 62

2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc xsd = xsd0 80 - 10.0.0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS +网络+服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 56

2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc xsd = xsd1 80 - 10.0。 0.1 Mozilla / 4.0 +(兼容; + MSIE + 6.0; + MS + Web +服务+客户端+协议+ 4.0.30319.34014) - 200 0 0 72



为什么我是否收到错误?如何解决?

I wrote a simple WCF Service Application. The service is deployed on a server with IP `10.0.0.14`. I can ping the server when I go to the URL :`http://10.0.0.14/jonts/WCFService.svc` from a desktop web browser and a mobile browser.

I have a Service interface that Implements REST that looks as follows:

namespace WCF_Connection
{

[ServiceContract]
public interface IWCFService
{
[OperationContract]
[WebGet(UriTemplate = "Test/{msg}")]
string sayHello(string msg);
}

}

When I use the WCF service by going to `http://10.0.0.14/jonts/WCFService.svc/test/one` I get a response with no problem. When I run the following in android I get a `connection to http://10.0.0.14 refused` error in the log.


private void Message()
{
HttpClient httpClient = new DefaultHttpClient();
try
{
String url = "http://10.0.0.14/jonts/WCFService.svc/test/dasd";

HttpGet method = new HttpGet( new URI(url) );
HttpResponse response = httpClient.execute(method);
Toast.makeText(getApplicationContext(),getResponse(response.getEntity()) ,
Toast.LENGTH_LONG).show();
} catch (IOException e) {
Log.e( "error", e.getMessage() );
} catch (URISyntaxException e) {
Log.e( "error", e.getMessage() );
}
}

My log from IIS is as follows:

#Software: Microsoft Internet Information Services 8.0
#Version: 1.0
#Date: 2014-07-01 08:20:09
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2014-07-01 08:20:09 10.0.0.14 GET /jonts/WCFService.svc - 80 - 10.0.0.1 Mozilla/5.0+(Windows+NT+6.3;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/35.0.1916.153+Safari/537.36 - 200 0 0 885
2014-07-01 08:20:23 10.0.0.14 GET /jonts/WCFService.svc - 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 84
2014-07-01 08:20:23 10.0.0.14 GET /jonts/WCFService.svc disco 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 43
2014-07-01 08:20:23 10.0.0.14 GET /jonts/WCFService.svc wsdl 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 74
2014-07-01 08:20:23 10.0.0.14 GET /jonts/WCFService.svc xsd=xsd0 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 546
2014-07-01 08:20:23 10.0.0.14 GET /jonts/WCFService.svc xsd=xsd1 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 93
2014-07-01 08:20:24 10.0.0.14 GET /jonts/WCFService.svc - 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 99
2014-07-01 08:20:24 10.0.0.14 GET /jonts/WCFService.svc disco 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 46
2014-07-01 08:20:24 10.0.0.14 GET /jonts/WCFService.svc wsdl 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 74
2014-07-01 08:20:24 10.0.0.14 GET /jonts/WCFService.svc xsd=xsd0 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 46
2014-07-01 08:20:24 10.0.0.14 GET /jonts/WCFService.svc xsd=xsd1 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 77
2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc - 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 106
2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc disco 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 46
2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc wsdl 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 73
2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc xsd=xsd0 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 46
2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc xsd=xsd1 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 79
2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc - 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 131
2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc disco 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 46
2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc wsdl 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 62
2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc xsd=xsd0 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 50
2014-07-01 08:20:35 10.0.0.14 GET /jonts/WCFService.svc xsd=xsd1 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 74
2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc - 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 102
2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc disco 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 39
2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc wsdl 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 62
2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc xsd=xsd0 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 49
2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc xsd=xsd1 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 73
2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc - 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 104
2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc disco 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 46
2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc wsdl 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 62
2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc xsd=xsd0 80 - 10.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 56
2014-07-01 08:21:02 10.0.0.14 GET /jonts/WCFService.svc xsd=xsd1 80 - 10.0.0.1 Mozilla/4.0+ (compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34014) - 200 0 0 72

Why do I get the error and How can I fix it?

推荐答案

这篇关于使用android消耗WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆