WCF Error: 客户端配置部分中,找不到引用协定{0}的默认终结点元素……

今天想验证一下System.ServiceModel.FaultException<T>,于是想通过一个Web页面调用WCF服务来弄一下。

可是了不幸的是Web层调用WCF的Client对象时报:“客户端配置部分中,找不到引用协定 的默认终结点元素……”,后来找了一下资料也算是解决了。

 

1. 服务端的配置(可以手写,也可用“WCF服务配置编辑器”)

 1 <system.serviceModel>
 2     
 3     <!--<services configSource="MyConfig\Debug\WCF.services.config"></services>-->
 4     <!--<bindings configSource="MyConfig\Debug\WCF.bindings.config"></bindings>-->
 5     <!--<client configSource="MyConfig\Debug\WCF.client.config"></client>-->
 6     <!--<behaviors configSource="MyConfig\Debug\WCF.behaviors.config"></behaviors>-->
 7 
 8     <bindings>
 9       <basicHttpBinding>
10         <binding name="JsonHelperBinding" />
11       </basicHttpBinding>
12     </bindings>
13     
14     <client>
15       <remove contract="IMetadataExchange" name="sb" />
16     </client>
17     
18     <behaviors>
19       <serviceBehaviors>
20         <behavior name="JsonHelperServiceBehavior">
21           <serviceMetadata httpGetEnabled="true" />
22         </behavior>
23       </serviceBehaviors>
24     </behaviors>
25     
26     <services>
27       <service behaviorConfiguration="JsonHelperServiceBehavior" name="ServiceImpl.JsonHelper">
28         <endpoint address=""
29                   binding="basicHttpBinding" 
30                   bindingConfiguration="JsonHelperBinding" 
31                   contract="IService.IJsonHelper" />
32         
33         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
34       </service>
35     </services>
36     
37   </system.serviceModel>

2. 客户端添加“服务引用”后自动生成的配置(app.config)

 1  <system.serviceModel>
 2         <bindings>
 3             <basicHttpBinding>
 4                 <binding name="BasicHttpBinding_IJsonHelper" closeTimeout="00:01:00"
 5                     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
 6                     allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
 7                     maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
 8                     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
 9                     useDefaultWebProxy="true">
10                     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
11                         maxBytesPerRead="4096" maxNameTableCharCount="16384" />
12                     <security mode="None">
13                         <transport clientCredentialType="None" proxyCredentialType="None"
14                             realm="" />
15                         <message clientCredentialType="UserName" algorithmSuite="Default" />
16                     </security>
17                 </binding>
18             </basicHttpBinding>
19         </bindings>
20         <client>
21             <endpoint address="http://localhost:2566/SVCJsonHelper.svc" binding="basicHttpBinding"
22                 bindingConfiguration="BasicHttpBinding_IJsonHelper" contract="JsonHelperService.IJsonHelper"
23                 name="BasicHttpBinding_IJsonHelper" />
24         </client>
25     </system.serviceModel>

3. 问题点:其实现在整个WCF服务已就绪,就是在Web层调用WCF客户端的时候报错了

1 ServicesClient.JsonHelperService.JsonHelperClient client = new ServicesClient.JsonHelperService.JsonHelperClient();

4. 我是这样解决的:
  1. 在我们的Web层不是也有一个"Web.confing"文件嘛,在里面新增一个标签:“<system.serviceModel>...{0}...</system.serviceModel>” (当然,请在Web层引用“System.ServiceModel”).

  2. 在客户端自动生成的那个配置文件(app.config)中,把<system.serviceModel></system.serviceModel>下的所有内容复制(Copy)到Web层,即上一步的{0}

 

转载于:https://www.cnblogs.com/Jagre/archive/2013/01/16/2862824.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值