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:远程服务 ...
随机推荐
- BZOJ3394: [Usaco2009 Jan]Best Spot 最佳牧场
3394: [Usaco2009 Jan]Best Spot 最佳牧场 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 11 Solved: 9[Sub ...
- leetcode-Consecutive numbers
Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...
- Ubuntu 14.04 64位安装Android Studio 和 genymotion (下)
接上一篇,上回书说到,我们可以进android studio的编辑器了.感觉不错.挺好的,先不说genymotion,先看看你的android项目有没有r文件,项目有没有错误? 如果没有问题的话,下面 ...
- 使用MapReduce将HDFS数据导入到HBase(二)
package com.bank.service; import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.conf. ...
- Java[2] 分布式服务架构之java远程调用技术浅析(转http://www.uml.org.cn/zjjs/201208011.asp)
转自:http://www.uml.org.cn/zjjs/201208011.asp 在分布式服务框架中,一个最基础的问题就是远程服务是怎么通讯的,在Java领域中有很多可实现远程通讯的技术,例如: ...
- 利用eclipse新建的java web项目没有部署描述符web.xml文件怎么办?
原文转自:http://blog.csdn.net/suyu_yuan/article/details/50947007 利用eclipse新建的Java Web项目没有部署描述符web.xml文件, ...
- JS-事件处理
1.一个简单的单击事件: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- script标签的位置
1.在我们编写代码的时候,会在页面内使用<script>标签来写JS,虽然理论上script标签的位置放在哪里可以,但是还是有一点区别的. 2.为什么很多人把script标签放在底部: 初 ...
- android4.4 settings 中控制卡1 卡2都振动
在package/app/Settings/src/com/android/settings/SoundSettings.java
- [转]iOS设备唯一标识探讨
转自:http://www.jianshu.com/p/b83b0240bd0e iOS设备唯一标识探讨 为了统计和检测应用的使用数据,几乎每家公司都有获取唯一标识的业务需求,在iOS5以前获取唯一标 ...