您的位置:首页 > 其它

创建WCF服务项目遇到的问题以及解决方法

2013-10-30 13:08 791 查看
1.“服务XXXXX有零个应用程序(非基础结构)终结点”。

产生原因:

<services>

<service name="DerivaticesClaculatorService.DerivaticesClaculatorServiceType" behaviorConfiguration="DerivaticesClaculatorService">

<host>

<baseAddresses>

<add baseAddress="http://localhost:7277/Claculator/"/>

</baseAddresses>

</host>

<endpoint address="http://localhost:7277/DerivaticesClaculatorServiceType/" binding="basicHttpBinding" contract="DerivaticesClaculatorService.IDerivativeCalculator">

</endpoint>

</service>

出现这个错误是因为service name由命名空间DerivaticesClaculatorService与提供的服务类名DerivaticesClaculatorServiceType组成,behaviorConfiguration是提供的服务类名,契约contract是命名控件DerivaticesClaculatorService和接口类IDerivativeCalculator组成.如果命名空间命或类名写错,或者写的不完全(比如只写了命名空间名字或者类名),则会出现上述错误。

解决办法:

1、按以上规则仔细核对。

2、如果实在找不到哪里写错,但程序还是报此错的话,还有一个办法:ServiceHost host = new ServiceHost(ServiceType) 改成

ServiceHost host = new ServiceHost(ServiceType,new Uri(http://localhost:7277/DerivaticesClaculatorServiceType/) ),也可以运行。

2.WCF服务发布以后,Client 端无法引用WCF服务,查看错误为“application soap+xml charset utf-8 客户端和服务绑定可能不匹配”。或者使用IE访问WCF服务地址的时候显示“当前已禁用此服务元数据的发布”。

(摘抄)按着《ASP.NET 3.5高级程序设计(第4版)》中的WCF案例一步步进行,书上说为了使初学者更好的关注WCF细节,先不使用WCF模版,但是进行到最后报出上述错误。书上写的配置是不包含<behaviors>节点的,这时Client 端无法正常连接服务,于是在网上各种找解决方法,在http://www.cnblogs.com/lanpei/archive/2009/10/29/1592218.html上找到累死问题解决方法,于是加上<behaviors>节点,此时仍然会报相同错误。因为书上的例子中没有<behaviors>节点,所以<service>节点中也不包含behaviorConfiguration属性,设置好behaviorConfiguration="CalculatorServiceBehavior",彻底没问题了。

按以上说法,我仔细核对了一下App.config文件

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<system.serviceModel>

<services>

<service name="DerivaticesClaculatorService.DerivaticesClaculatorServiceType"
behaviorConfiguration="DerivaticesClaculatorService">

<host>

<baseAddresses>

<add baseAddress="http://localhost:7277/Claculator/"/>

</baseAddresses>

</host>

<endpoint address="http://localhost:7277/DerivaticesClaculatorServiceType/" binding="basicHttpBinding" contract="DerivaticesClaculatorService.IDerivativeCalculator">

</endpoint>

</service>

</services>

<behaviors>

<serviceBehaviors>

<behavior name="DerivaticesClaculatorService">

<serviceMetadata httpGetEnabled="true" />

</behavior>

</serviceBehaviors>

</behaviors>

</system.serviceModel>

</configuration>

其中的behavio段要设置好,前后要一致。

然后添加服务引用

注意服务引用的地址是baseAddress="http://localhost:7277/Claculator/",一定一定不要写成endpoint address="http://localhost:7277/DerivaticesClaculatorServiceType/“的了,这样就会报上面的错!

先暂时这么多,待补充。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: