简化配置wsHttpBinding

时间:2012-05-08 12:06:00

标签: wcf binding

我有一个简单的WCF服务,部署到IIS。我将simplified configurationBasicHttpBinding一起使用,效果很好。

现在我想添加用户名/密码身份验证并使用wsHttpBinding。在上面的文件中说明:

  

在.NET Framework 4中,元素是可选的。当一个服务   没有定义任何端点,每个基地址的端点和   已实施的合同将添加到服务中。基地址是   附加到合同名称以确定端点和   绑定由地址方案确定

这意味着什么,我应该如何通过地址方案配置wsHttpBinding绑定?

我的配置如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding>
          <security mode="Message">
            <transport clientCredentialType="None"/>
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>      
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior> 
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="SampleWebservice.CustomValidator,SampleWebservice" />
          </serviceCredentials>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>  
</configuration>

这是Windows Server 2008,IIS 7。

看来,该服务没有获取wsBinding设置,因为我总是可以在下载的svc文件中看到BasicHttpBinding。我错过了什么吗?


修改

我应用了用户stevedocious建议的更改来修改我的web.config文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="SampleWebservice.SampleWebservice.Sample" behaviorConfiguration="customServiceBehaviour">
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
        <endpoint contract="SampleWebservice.SampleWebservice.ISample" binding="wsHttpBinding" bindingConfiguration="bindingConfiguration" address="" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="bindingConfiguration">
          <security mode="Message">
            <transport clientCredentialType="None"/>
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>      
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="customServiceBehaviour"> 
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="SampleWebservice.CustomValidator,SampleWebservice" />
          </serviceCredentials>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>  
</configuration>

但是,无法公开元数据。使用浏览器检查服务状态,我的元数据发布当前已禁用。

1 个答案:

答案 0 :(得分:2)

如果您想使用除http / https地址方案的basicHttpBinding以外的任何其他内容,则需要创建一个端点。

在绑定定义中添加名称属性

  

&LT; binding name =“myWSBinding”...&gt;

然后将bindingConfiguration和binding参数添加到端点定义

  

&LT; endpoint binding =“wsHttpBinding”bindingCongifuration =“myWSBinding”...&gt;