如何设置HTTP和HTTPS WCF 4 RESTful服务? [英] How do you setup HTTP and HTTPS WCF 4 RESTful services?

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

问题描述

我正在尝试使用WCF 4设置RESTful Web服务.我希望可以同时使用HTTP和HTTPS访问该服务.默认情况下,使用以下配置创建服务,该配置适用于http而不适用于https:

I'm trying to use WCF 4 to set up a RESTful web service. I'd like the service to be accessible both using HTTP and HTTPS. By default the service is created with the following configuration which works for http but not https:

<system.serviceModel>
 <behaviors>
   <endpointBehaviors>
     <behavior>
       <webHttp helpEnabled="true" />
     </behavior>
   </endpointBehaviors>
 </behaviors>
 <protocolMapping>
   <add scheme="http" binding="webHttpBinding" />
 </protocolMapping>
</system.serviceModel>

然后我可以通过将配置略微更改为以下内容来打开该服务的HTTPS:

I can then turn on HTTPS for the service by changing the configuration slightly to this:

<system.serviceModel>
 <behaviors>
   <endpointBehaviors>
     <behavior>
       <webHttp helpEnabled="true" />
     </behavior>
   </endpointBehaviors>
 </behaviors>
 <bindings>
   <webHttpBinding >
     <binding name="SecureWebBinding" >
       <security mode="Transport"></security>
     </binding>
   </webHttpBinding>
 </bindings>
 <protocolMapping>
   <add scheme="http" binding="webHttpBinding"  bindingConfiguration="SecureWebBinding"/>
 </protocolMapping>
</system.serviceModel>

我的问题是如何使服务与两者同时使用?

My question is how do I get the service working with both?

推荐答案

您应该尝试创建两个单独的端点.例如,

You should try to create two separate end-points. For example,

<system.serviceModel>
    <services>
       <service name="MyNameSpace.MyService">
           <endpoint address="https://www.example.com/MyService.svc"
                  binding="wsHttpBinding" bindingConfiguration="SecureWebBinding"
                  contract="MyNameSpace.IMyContract" />
           <endpoint address="http://www.example.com/MyService.svc"
                  binding="basicHttpBinding" 
                  contract="MyNameSpace.IMyContract" />
       </service>

       <bindings>
           <webHttpBinding >
              <binding name="SecureWebBinding" >
                 <security mode="Transport"></security>
              </binding>
           </webHttpBinding>
       </bindings>

    </services>
</system.serviceModel>

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

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