如何在WCF RESTful服务上启用HTTPS? [英] How to enable HTTPS on WCF RESTful Service?

查看:79
本文介绍了如何在WCF RESTful服务上启用HTTPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使wcf在https上工作.我想在https上使用此wcf我已经搜索了很多文章,但没有得到答案,请帮助iam刚接触wcf概念.我想从ajax,jquery调用它

How to make wcf to work over https. I want to use this wcf over https i have searched many articles i didn't get the answer please help iam new to wcf concepts. I want to call it from ajax,jquery

 <system.serviceModel >
<services>
  <service
    name="WcfRestfulService.HttpService" behaviorConfiguration="ServiceBehaviour" >
    <endpoint address="" binding="webHttpBinding" behaviorConfiguration="web"
              contract="WcfRestfulService.IHttpService">
    </endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata 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="false"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>

推荐答案

似乎您正在使用WCF构建RESTful服务,并且真的很接近对其进行保护.

It appears you are building a RESTful Service with WCF and you are really close to securing it.

您需要执行以下操作来保护它:

Here is what you need to do to secure it:

  1. 添加一个新的 WebHttpBinding 配置,该配置的安全模式设置为 Transport .
  2. 将新的 WebHttpBinding 配置分配给您的服务端点绑定.
  3. 通过设置 httpGetEnabled ="false" ,确保只能通过HTTPS访问RESTful服务.
  4. 设置元数据发布终结点以使用HTTPS.
  1. Add a new WebHttpBinding configuration that has security mode set to Transport.
  2. Assign that new WebHttpBinding configuration to the your Service Endpoint binding.
  3. Make sure that your RESTful service can only be accessed via HTTPS by setting httpGetEnabled="false".
  4. Set up the metadata publishing endpoint to use HTTPS.

这些更改都汇总在下面的修订后的配置文件中(有关更改之处,请参见注释).另外请注意,您的服务端点必须使用HTTPS方案,而不是HTTP.

These changes are all summed up below in the revised configuration file (see comments for points that changed). Also note that your Service Endpoint must be using the HTTPS scheme and not HTTP.

<system.serviceModel >
  <services>
     <service name="WcfRestfulService.HttpService"
              behaviorConfiguration="ServiceBehaviour" >
         <endpoint address="" 
                   binding="webHttpBinding"
                   <!-- Add reference to secure WebHttpBinding config -->
                   bindingConfiguration="webHttpTransportSecurity"
                   behaviorConfiguration="web"
                   contract="WcfRestfulService.IHttpService" />
         <!-- Need to make sure that our metadata 
              publishing endpoint is using HTTPS as well -->
         <endpoint address="mex"
                   binding="mexHttpsBinding"
                   contract="IMetadataExchange" />
     </service>
  </services>
  <!-- Add secure WebHttpBinding config -->
  <bindings>
     <webHttpBinding>
        <binding name="webHttpTransportSecurity">
           <security mode="Transport" />
         </binding>
      </webHttpBinding>
  </bindings>
  <behaviors>
      <serviceBehaviors>
         <behavior name="ServiceBehaviour">
             <serviceMetadata httpsGetEnabled="true"
                              <!-- Make sure the service can 
                                 be accessed only via HTTPS -->
                              httpGetEnabled="false"/>
             <serviceDebug includeExceptionDetailInFaults="false"/>
         </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
         <behavior name="web">
             <webHttp/>
         </behavior>
      </endpointBehaviors>
  </behaviors>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>

这篇关于如何在WCF RESTful服务上启用HTTPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆