使用wsHttpBinding,WCF忽略了我的web.config

时间:2013-04-07 23:02:08

标签: c# .net wcf

我正在尝试创建一个需要会话支持的WCF服务,所以我在web.config中添加了一个部分来启用wsHttpBinding。但是,当我在WCF测试客户端中测试服务并检查配置时,它似乎采用了默认的自动生成的配置而不是我自己的配置。

参见我的配置:

<?xml version="1.0"?>
<configuration>
<system.web>

<compilation debug="true" targetFramework="4.0" />
</system.web>
  <system.serviceModel>

<behaviors>
  <serviceBehaviors>

    <behavior>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>    
  </serviceBehaviors>
</behaviors>

<services>
  <service name="UserService">
    <endpoint address="" binding="wsHttpBinding" contract="ICenterPlaceUserService" />
  </service>
</services>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

                   

结果:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_ICenterPlaceUserService" sendTimeout="00:05:00" />
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:57418/L1.WCF/CenterPlaceUserService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICenterPlaceUserService"
            contract="ICenterPlaceUserService" name="BasicHttpBinding_ICenterPlaceUserService" />
    </client>
</system.serviceModel>

我错过了什么?

1 个答案:

答案 0 :(得分:11)

name属性的<service>属性必须具有服务类的完全限定名称。否则它将被忽略,您将看到您所看到的行为:默认绑定用于服务(basicHttpBinding)。

<services>
  <service name="TheNamespaceOfYourClass.UserService">
    <endpoint address=""
              binding="wsHttpBinding"
              contract="TheNamespaceOfYourContract.ICenterPlaceUserService" />
  </service>
</services>