[英]wcf userName authentication with message security over https
在這種情況下,我希望許多客戶端使用通過https的用戶名身份驗證來調用我的Web服務。 安全是第一要務,因此我正在考慮將wshttpbinding與消息安全一起使用。 我不知道我的想法是否正確。 事實是,我已經可以使用某些功能,但是我不知道是否需要進行更改才能獲得更好的安全性。 到目前為止,這是完成的操作。
<services>
<service name="myService" behaviorConfiguration="myBehavior" >
<endpoint address="" binding="basicHttpBinding" contract="myIService" bindingConfiguration="RequestUserName_BasicHttp" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/myService/" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="RequestUserName_BasicHttp">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="myvalidator, myNamespace"/>
</serviceCredentials>
因此,通過這種方式(有效),我認為我沒有最好的安全性(至少我需要通過https發送請求)。 我該怎么做才能獲得更好/最好的安全性? 我已經嘗試過wshttpbinding和https,但是證書存在一些問題。 開發環境是Windows XP,VS2010,IIS7.5 Express。 還有一個描述服務的類庫和一個使用它的consoleClient應用...客戶端具有它自己的app.config文件,其中包含憑據(用戶名和密碼)。
您已經在實現用戶ID和密碼驗證,並且如果要執行消息的加密和解密,則必須使用帶有HttpsBinding或WsHttpBinding的證書。 有關WCF中身份驗證和授權的更多信息,請查閱此MSDN文檔
好的,我考慮了Ramesh Babu的回答,並更改了我的項目。 因此,我沒有為WCF服務創建類庫,而是創建了WCF服務應用程序(VS2010中有此選項),其他所有東西都保持不變,所以我制作了一個新的Web.config文件,如下所示
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MyBinding">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="MyBehavior" name="myName">
<endpoint address="myService.svc" binding="wsHttpBinding"
bindingConfiguration="MyBinding"
contract="myService.ImyService" />
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:44400/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebugincludeExceptionDetailInFaults="true" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="myService.Authentication.CustomValidator, myService" />
<serviceCertificate
findValue="MyCertificate"
x509FindType="FindBySubjectName"
storeLocation="LocalMachine"
storeName="My" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
<connectionStrings>
<add name="myEntities" connectionString="......" />
</connectionStrings>
</configuration>
因此我需要創建一個證書,並使用SelfCert創建一個證書並將其復制到TrustedPeople(在運行時鍵入mmc)。 此后,我創建了一個控制台應用程序以使用該服務,並且該應用程序的app.config文件是自動構建的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.