我创建了一个wcf服务,托管它在IIS(7.5),它工作正常。我现在想添加用户名认证,并遇到一些问题。 配置文件是这样的:WCF问题 - wsHttpBinding与用户名认证和TransportWithMessageCredentials
<system.serviceModel>
<services>
<service behaviorConfiguration="warServBehavior" name="WcfServiceLibrary.WarcraftService">
<endpoint address="" binding="wsHttpBinding" contract="WcfServiceLibrary.IWarcraftService" bindingConfiguration="warWsHttpBinding" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="warWsHttpBinding">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None"/>
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="warServBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="BogusValidator, App_Code"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
关于证书我做了以下(从MSDN启发):
1)makecert -n “CN = RootCATest” -r -sv RootCATest。 PVK RootCATest.cer
2)将其添加到受信任的根证书颁发机构
- 3)makecert -sk CertTest -iv RootCATest.pvk -n “CN =虚假” -ic RootCATest.cer - SR LOCALMACHINE -ss我-sky交换-pe
在IIS我增加了对HTTPS,并在服务器证书我有这个结合:
当我运行SvcUtil工具https://localhost/WarcraftServiceSite/WarService.svc我得到这个异常: "There was an error downloading https://localhost/WarcraftServiceSite/WarService.svc. The underlying connection was closed.Could not establish trust relationship for the SSL/TLS secure channel. The remote certificate is invalid according to the validation procedure."
后来编辑:看来,叫SvcUtil工具的正确方法是使用HTTP没有使用https,即使我有这个<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />