保护WCF服务
本文关键字:服务 WCF 保护 | 更新日期: 2023-09-27 17:53:33
我在控制台应用程序和访问其操作的web应用程序上托管了WCF服务。我搜索了WCF安全性,在大多数情况下,web服务托管在IIS上。在我的情况下,为了实现WCF传输层安全,我应该遵循哪些要点?
我想要的是
- 使用用户名和密码执行WCF操作
- 使用SSL加密数据
如果我的WCF服务托管在控制台应用程序上。我应该做什么IIS配置吗?
如果你想通过HTTP公开WCF服务,你可以使用自定义配置的BasicHttpBinding:
<bindings>
<basicHttpBinding>
<binding name="secured">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="userName" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="securedService">
<serviceMetadata httpsGetEnabled="true" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Namespace.Type, assembly" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Namespace.Type" behaviorConfiguration="securedService">
<host>
<baseAddresses>
<!-- some url -->
<baseAddress baseAddress="https://localhost:8088/Service" />
</baseAddresses>
</host>
<endpoint address="" contract="Namespace.Type" binding="basicHttpBinding" bindingConfiguration="secured" />
<endpoint address="mex" contract="IMetadataExchange" binding="mexHttpsBinding" />
</service>
</services>
这将使用HTTPS和UserName令牌配置文件创建SOAP 1.1服务,以便在消息中传输凭据。它还将通过HTTPS公开元数据(WSDL),用户名和密码将由自定义验证器进行验证。默认验证验证windows帐户,但也可以将其重新配置为使用ASP。. NET成员资格提供程序。
您需要做的最后一件事是在使用的端口上允许HTTPS(在本例中为8088)。为此,您需要将带有私钥的证书安装在机器上的证书存储库中(应该在LocalMachine的My/Personal存储库中)。您可以创建自签名证书用于测试。
获得证书后,必须使用netsh将证书分配给端口。您还应该允许应用程序通过使用netsh在端口上侦听,否则您的控制台应用程序将不得不以管理员身份运行(UAC - Windows Vista, 7, 2008, 2008 R2)。
如果你的WCF服务托管在控制台应用程序中,IIS与它们无关,所以你不需要配置IIS或其他任何东西。
为了保证传输层的安全性,可以将WsHttp或netttcp绑定与SSL结合使用。
查看http://www.dotnetspark.com/kb/1502-security-wcf--transport-level.aspx, http://www.packtpub.com/article/microsoft-wcf-security和http://dotnetrobert.com/?q=node/140