繁体   English   中英

启用HTTPS的IIS托管WCF服务,如何保护它?

[英]HTTPS-enabled, IIS hosted WCF service, How to secure it?

我建立了一个相当简单的WCF服务,该服务托管在IIS 7.5实例上。 我已经完成了必要的步骤来保护SSL证书以启用https。 我已经解决了所有各种DNS设置,因此现在可以从世界各地的给定Https:// URL进入WCF了。 目标是:为大约5个将数据发送到服务的客户端进行某种客户端/服务器身份验证。 确保这项服务的最佳方法是什么? 此时,只有一种方法非常简单。 我确定web.config以及背后的代码都会有所变化。 实例不胜感激。

这是Web.config

<!-- language: lang-xml -->
    <?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>

  <services>
    <service name="wcflistener.Service1">
      <endpoint address=""           
      binding="basicHttpBinding"
      bindingConfiguration="secureHttpBinding"
      contract="wcflistener.IService1"/>

      <endpoint address="mex"
      binding="mexHttpsBinding"
      contract="IMetadataExchange" />
    </service>
  </services>

  <bindings>
    <basicHttpBinding>
      <binding name="secureHttpBinding">
        <security mode="Transport">
          <transport clientCredentialType="None"/>
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- 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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
    -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

和非常简单的Service1.svc.cs

 [DataContract]
public class Service1 : IService1
{


    public void SampleMethod(DataTable table, string name)
    {
        //sample method logic here
    } 
}

使用WCF,您可以使用几种安全选项,各有其优缺点:

  1. SSL + Windows身份验证的使用。 (这对于Internet托管服务通常很困难,因为每个人都需要与同一个域控制器进行对话)
  2. SSL +用户名/密码:WCF可以轻松地实现此目的,客户端传递用户名/密码,并且服务可以使用预先配置的值来验证值并允许客户端进一步使用。
  3. 基于证书的身份验证:通常,可以为客户端提供服务器证书的公钥,以便他们可以使用该证书来调用服务。 但是,这不能完全识别客户端。 任何人都可以获取您的公钥。
  4. 相互证书或双向SSL:这是客户端拥有私钥并将公钥提供给服务的时间。 反之亦然,即服务将其公钥提供给客户端。

这取决于您需要的身份验证级别。 对于很少的客户,用户名/密码就足够了。 (始终有失去这些风险)

对于主要客户2 SSL非常安全,因为人们不会轻易丢失私钥。

根据您的选择,可以共享其他代码示例。

对于选项#,请单击此链接。 (您可以在以下步骤中使用SSL证书)

http://codebetter.com/petervanooijen/2010/03/22/a-simple-wcf-service-with-username-password-authentication-the-things-they-don-t-tell-you/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM