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:远程服务 ...
随机推荐
- tarjan缩点
整理了下模板... #include<iostream> #include<cstdio> #include<cmath> #include<algorith ...
- http协议使用实例
#include <stdio.h>#include <windows.h>#include <wininet.h> #define MAXSIZE 1024#pr ...
- bzoj2019 [Usaco2009 Nov]找工作
Description 奶牛们没钱了,正在找工作.农夫约翰知道后,希望奶牛们四处转转,碰碰运气.而且他还加了一条要求:一头牛在一个城市最多只能赚D(1 <= D <= 1,000)美元,然 ...
- Codeforces Round #236 (Div. 2)E. Strictly Positive Matrix(402E)
E. Strictly Positive Matrix You have matrix a of size n × n. Let's number the rows of the matrix f ...
- MD中bitmap源代码分析--入题概述
在MD模块中,各级raid都使用的一份bitmap的源码,也就是说共用一种bitmap的流程,下面以raid1的使用为例来分析bitmap的工作原理. 在使用raid1磁盘阵列的时候,对于数据的可靠性 ...
- zookeeper[3] zookeeper API开发注意事项总结
如下是根据官方接口文档(http://zookeeper.apache.org/doc/r3.4.1/api/org/apache/zookeeper/ZooKeeper.html#register( ...
- 双外边距浮动bug;3像素文本偏移bug;IE6以下相对定位中的绝对定位bug
http://www.cnblogs.com/star91/p/5458100.html
- ORACLE_CLASS_ENDING
[JSU]LJDragon's Oracle course notes In the first semester, junior year Oracle考前复习 试题结构分析: 1.选择题2x10, ...
- JavaScript学习笔记(高级部分—01)
JavaScript的核心ECMAScript描述了该语言的语法和基本对象:DOM描述了处理网页内容的方法和接口:BOM描述了与浏览器进行交互的方法和接口. 简单说,ECMAScript描述了以下内容 ...
- LIB文件和DLL文件的作用
(1)lib是编译时需要的,dll是运行时需要的.如果要完成源代码的编译,有lib就够了.如果也使动态连接的程序运行起来,有dll就够了.在开发和调试阶段,当然最好都有.(2)一般的动态库程序有lib ...