我有一个简单的 WCF 服务,部署到 IIS。我使用了简化的配置,BasicHttpBinding
效果很好。
现在我想添加用户名/密码身份验证并使用 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 设置,因为我总是可以BasicHttpBinding
在下载的 svc 文件中看到一个。我错过了什么吗?
编辑
我应用了用户 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>
但是,不能公开元数据。使用浏览器检查服务状态,我的元数据发布当前被禁用。