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:远程服务 ...
随机推荐
- Android 使用Application总结
Application 配置全局Context 第一步.写一个全局的单例模式的MyApplication继承自Application 覆盖onCreate ,在这个方法里面实例化Application ...
- rsyslog Properties 属性:
rsyslog Properties 属性: 数据项 在rsyslog 是被称为 "properties". 它们可以有不同的源, 最重要的是 那些来自接收的消息,但是还有其他. ...
- sigaction
概述编辑 sigaction(查询或设置信号处理方式) 相关函数 signal,sigprocmask() ,sigpending,sigsuspend, sigemptyset 表头文件 #incl ...
- Android读取Assert文件夹下txt文本并变为String的方法
使用场景,在assert文件夹下 有些文本文件,我们需要通过工具类读取出来,然后放到String字符串中,我们该如何操作呢: 直接上代码: 使用方法: MyActivity.readAssertRes ...
- 重温Java的类加载机制
原文地址:http://blog.csdn.net/hitxueliang/article/details/19992851 首先简要的说一下类加载器 我们知道,虚拟机的指令存储在以.class为 ...
- cf202-div 1-B - Apple Tree:搜索,数论,树的遍历
http://codeforces.com/contest/348/problem/B B. Apple Tree time limit per test 2 seconds memory l ...
- appium 使用findElementByAndroidUIAutomator 定位元素示例
appium 使用findElementByAndroidUIAutomator 定位元素示例 import io.appium.java_client.remote.MobileCapability ...
- 菜单栏始终浮动在顶部 js
//菜单栏始终浮动在顶部var navH = $(".trade-tab-bot").offset().top;//获取要定位元素距离浏览器顶部的距离//滚动条事件$(window ...
- HDU4662+无
把目标中的 U 转化为 I. 又因为 I的个数是有规律的:1 2 4 8 16 ...再结合可以取消 6 12 18 ...个I...得解 #include<string.h> #incl ...
- Win8.1OS64位oracle11安装配置及PL/SQL Developer怎样连接64位oracle
Oracle 为什么选择oracle 1.oracle可以在主流的平台上执行,而相对于sql server仅仅支持windows,而windows在wr手里攥着呢,所以你懂的.在安全性上来讲,非常多地 ...