WCF-IIS-PDA
PDA调用WCF
一 IIS托管WCF
项目从开始是用IIS托管的WCF,但一直出错,到最后也没有搞定,希望哪位大神知道的话可以指点。
错误如下:
There was no endpoint listening at http://mypcname/Service1.svc/basic that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The inner exception: Could not establish connection to network.
虽然项目没有成功,但还是学到了一些东西,总结以备以后之用。
(1)在IIS上部署WCF
具体的发布流程网上很多,可以参考这篇:http://www.cnblogs.com/finehappy/archive/2009/12/22/1629483.html。但发布完之后可能出现很多问题:
Question 1:
在VS中,添加服务引用,地址输入http://ip/Service.svc,点击前往,提示错误,内容如下:
URI http://ip/Service.svc 处的文档未被识别为已知的文档类型。
来自各已知类型的错误信息可能有助于修复该问题:
- 来自“XML 架构”的报告是“无法识别此文档格式(内容类型为“text/html; charset=UTF-8”)。”。
- 来自“http://ip/Service.svc”的报告是“无法识别此文档格式(内容类型为“text/html; charset=UTF-8”)。”。
- 来自“DISCO 文档”的报告是“下载“http://域名/Service.svc?disco”时出错。”。
- 未能解析此远程名称: '域名'
- 来自“WSDL 文档”的报告是“无法识别此文档格式(内容类型为“text/html; charset=UTF-8”)。”。
元数据包含无法解析的引用:“http://域名/Service.svc”。
服务 http://ip/Service.svc 不支持内容类型 application/soap+xml; charset=utf-8。客户端和服务绑定可能不匹配。
远程服务器返回错误: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.。
如果该服务已在当前解决方案中定义,请尝试生成该解决方案,然后再次添加服务引用.
解决方案:
修改wcf的配置文件,添加红色部分部门,或者通过wcf配置文件编辑器,添加useRequestHeadersForMetadataAddress配置
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="http" port="" />
<add scheme="https" port="" />
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
</behaviors>
Question 2:.net程序集过时问题
错误代码:
未能加载文件或程序集“xxx”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集
解决方案:
主要原因是:引用的项目 .net 版本与启动的框架不同
主要原因是:引用的项目 .net 版本与启动的框架不同 windows xp 我的电脑->右键管理->Internet信息服务->默认网站->右键属性->ASP.NET->> 更改相应的asp.net版本即可 windows 7 我的电脑->右键管理->Internet信息服务(IIS)管理器->双击打开->单击应用程序池->双击要修改的网站->将.NET Framework 版本修改为相对应的版本即可
二 其他host wcf 平台
1.启动服务端发布服务
这里为了简单,我使用console程序进行发布。最关键的还是Uri和binding,如果想在PDA上调用wcf服务,那么binding必须采用BasicHttpBinding,这点必须注意。
Uri baseUri = new Uri("http://localhost:8080/wcfService");
using (ServiceHost wcfServiceHost = new ServiceHost(typeof(Service.WcfServcie), baseUri))
{
BasicHttpBinding binding = new BasicHttpBinding();
wcfServiceHost.AddServiceEndpoint(typeof(IWcfServcie), binding, string.Empty);
ServiceMetadataBehavior behavior = wcfServiceHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (behavior == null)
{
behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
behavior.HttpGetUrl = baseUri;
wcfServiceHost.Description.Behaviors.Add(behavior);
}
else
{
behavior.HttpGetEnabled = true;
behavior.HttpGetUrl = baseUri;
}
wcfServiceHost.Open();
Console.Read();
}
2、检查服务是否已发布
编译后启动服务端程序,使用“:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\WcfTestClient.exe”,可以检查服务是否正常发布,当然也可以使用IE。我一般使用WcfTestClient.exe,它可以针对每个方法做测试。
3、创建PDA上WCF服务代理类
可以手动写这部分代码,如果不想自己写代理类,那就下载NETCFv35PowerToys.msi并安装,然后“:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\bin”会有一个程序NetCFSvcUtil.exe。通过cmd执行“NetCFSvcUtil.exe http://localhost:8080/wcfService" ,\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\bin目录下会出现生成的两个文件CFClientBase.cs和WcfServcie.cs,这就是服务的代理类。需要注意的是WcfServcie.cs中”public static System.ServiceModel.EndpointAddress EndpointAddress = new System.ServiceModel.EndpointAddress("http://localhost:8080/wcfService");“,将”localhost“改为服务端的Ip。
在win7上NetCFSvcUtil.exe可能不起作用,总会提示外部工具错误。所以最好用win7之前的OS。不过微软已经发布一个补丁版本。可以搜下。
WCF-IIS-PDA的更多相关文章
- 【记录】WCF IIS 404
WCF IIS 发布报"404错误": 修改 Web.config 如下: <system.webServer> <handlers> <remove ...
- wcf iis host 打开exe失败 不能显示界面
最近谷歌没法用了,我的freegate经常性的崩溃 无奈之下,用了必应,貌似也不错 http://stackoverflow.com/questions/8414514/iis7-does-not-s ...
- WCF - IIS Hosting
WCF - IIS Hosting Hosting a WCF service in IIS (Internet Information Services) is a step-by-step pro ...
- [WCF]IIS部署到新系统
最近为以前的一个企业部署软件的时候,接触到WCF,通过博客园大佬的系列文章和一些书籍,基本了解了一些.简单说也算是SOA一种方式,提供某种服务,可以理解为一个类库,供其他项目使用,可以做到业务分离.但 ...
- WCF IIS 部署错误处理
做Web接口,原来一直用Web Service的,但是.Net 3.5后,Web Service变成了WCF.代码的编写上,把WebMethod特性改成了OperationContract,然后把方法 ...
- WCF IIS上部署服务
一.选择应用程序池:.Net Framework 4.0集成模式 二.IIS Access is denied:程序所在文件夹给予Everyone权限 三.HTTP 错误 500.21 - Inter ...
- WCF IIS部署
创建WCFHost应用程序 Iservice.cs using System; using System.Collections.Generic; using System.Linq; using S ...
- 在 IIS 6 和 IIS 7中配置Https,设置WCF同时支持HTTP和HTPPS,以及使用HttpWebRequest和HttpClient调用HttpS
IIS 7 ,给IIS添加CA证书以支持https IIS 6 架设证书服务器 及 让IIS启用HTTPS服务 WCF IIS 7中配置HTTPS C#利用HttpWebRequest进行post请求 ...
- Deploying an Internet Information Services-Hosted WCF Service
Deploying an Internet Information Services-Hosted WCF Service .NET Framework 4 Other Versions .NET ...
- WCF RIA Services异常
.svc处理程序映射缺失导致的WCF RIA Services异常 在确定代码.编译结果和数据库都正常的情况下,无法从数据库取到数据.错误提示:Sysyem.Net.WebException:远程服务 ...
随机推荐
- 华夏的理财30天A和华夏财富宝货币哪个收益比较好?
1.收益性比较 华夏理财30天A001057属于债券型基金,华夏财富宝货币000343属于货币型基金(活期宝,类似余额宝)收益不同 2.流动性 活期宝是可以随时取现的产品,30天A是有封闭期的产品,这 ...
- 【android】adb连接几个常见问题(遇到再新增)
不知道为什么,每次连接手机,都提示 adb server is out of date,偶尔也会提示not found 每次去百度,都好多方法---终于有一种方法非常靠谱,遂,记录之--- 问题一:o ...
- hdu4111 Alice and Bob
Alice and Bob Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 远程连接mysql
win系统下,连接别人的mysql或者让别人链接自己的mysql: 打开命令行cmd 进入mysql: mysql -u root -p mysql>use mysql; mysql>s ...
- Gson 基础教程 —— 自定义类型适配器(TypeAdapter)
1,实现一个类型适配器(TypeAdapter) 自定义类型适配器需要实现两个接口: JsonSerializer<T> JsonDeserializer<T> 和两个方法: ...
- Python Cookbook笔记
字符串:s.strip() 删除字符串开始和结尾的空白字符. s.lstrip() 删除左边的,s.rstrip() 删除右边的. 随机数:random.random() 生成0-1之间的数. ...
- AVC1与H264的差别
今天上网时偶尔发现这个在我脑海里疑惑的问题的答案. H.264 Video Types The following media subtypes are defined for H.264 video ...
- Java static块
首先,我们看一个实际例子: class Test{ public static int X=100; public final static int Y=200; public Test(){ Sys ...
- Java基础知识强化39:StringBuffer类之StringBuffer的删除功能
1. StringBuffer的删除功能: public StringBuffer deleteCharAt(int index):删除指定位置的字符,并返回字符串缓冲区本身. public Str ...
- linux中文乱码问题及locale详解
一.修改系统默认语言及中文乱码问题记录系统默认使用语言的文件是/etc/sysconfig/i18n,如果默认安装的是中文的系统,i18n的内容如下: LANG="zh_CN.UTF-8&q ...