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

标签 c# .net wcf

我正在尝试创建一个需要 session 支持的 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>

我错过了什么?

最佳答案

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

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

关于c# - 使用 wsHttpBinding,WCF 忽略了我的 web.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15868890/

相关文章:

c# - 如何获得年/月/周/日中两个日期之间的差异?

c# - Ria 服务将复杂对象作为参数传递给查询域服务方法

c# - 如何将 RichTextBox 滚动到底部?

c# - 使用 WCF 和 Java 编写的 Web 服务

c# - Asp.Net 刷新页面的静态方法

c# - 为 RESTful WCF 配置 SSL 绑定(bind)。如何?

c# - 在可序列化字典上使用 foreach 语句

wcf - 为WCF服务添加多个HTTP基地址

c# - WPF 将应用程序命令绑定(bind)到 ViewModel ICommand

c# - 如何在 C# 中查找最新版本的文件名