我創建了一個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" />