几天来我一直在尝试正确保护我的 WCF WebService,但现在遇到了障碍。我尝试在不使用证书的情况下保护此 WebService,因为它将在安全的 Intranet 内运行。
我希望能够通过用户名/密码保护 WebService,而无需更改验证用户名和密码的每种方法,也无需使用证书。这可能吗:
我当前的 web.config 如下:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="TestWS.Service1" behaviorConfiguration="Default">
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
<endpoint contract="TestWS.IService1" binding="wsHttpBinding" bindingConfiguration="Binding1" address="" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="Binding1">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Default">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="TestWS.Validation.VanguardValidator, TestWS" />
</serviceCredentials>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
提前致谢,
帕特里克
最佳答案
如果您使用用户名/密码验证,您可能会在消息中以纯文本形式发送凭据。因此,您要么需要使用传输级 (SSL) 安全性 (https://....
),要么您必须在服务器端拥有证书来提供共享的方式Secret 以便客户端和服务器之间的消息可以被加密和签名。或者,如果您根本不需要任何东西,也可以完全关闭安全性。
参见Fundamentals of WCF Security有关 WCF 安全性的精彩介绍,请访问 MSDN docs on Programming WCF Security ,或 Juval Löwy 关于 Declarative WCF Security 的优秀 MSDN 文章
关于.net - 不使用证书保护 WCF WebService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5196828/