WebHttpBinding与Http和Https [英] WebHttpBinding with Http and Https

查看:106
本文介绍了WebHttpBinding与Http和Https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用https&网站的http.该网站具有.svc文件,这些文件充当REST服务并通过JavaScript调用.

I am trying to use https & http for the website. The website has .svc files which act as REST service and called from JavaScript.

我的配置:

<system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="AjaxBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehaviour">
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="true"/>         
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <services>
      <service behaviorConfiguration="MyServiceBehaviour" name="MyService.Lookups">
        <endpoint address="" behaviorConfiguration="AjaxBehavior"
          binding="webHttpBinding" bindingConfiguration="httpWebBinding" contract="MyService.Lookups" >         
        </endpoint>
        <endpoint address="" behaviorConfiguration="AjaxBehavior"
          binding="webHttpBinding" bindingConfiguration="httpsWebBinding" contract="MyService.Lookups" >          
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <bindings>      
      <webHttpBinding>
        <binding name="httpsWebBinding">
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None" />
          </security>
        </binding>
        <binding name="httpWebBinding">
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>   
  </system.serviceModel>

浏览 https://myserver/services/Lookups.svc/Hello 给予

找不到与绑定WebHttpBinding的终结点计算机的方案http匹配的基地址.注册的基本地址方案为[https]

浏览 http://myserver/services/Lookups.svc/Hello 给予

找不到与具有绑定的WebHttpBinding的端点的方案https匹配的基地址.注册的基址方案为[http]

如果我删除任何一个端点,它将起作用.删除使用 bindingConfiguration ="httpWebBinding" 配置的端点的示例适用于HTTPS,

If I remove any one endpoint it works. Example removing endpoint configured with bindingConfiguration="httpWebBinding" works for HTTPS ,

如何使其与HTTP和HTTPS一起使用?到目前为止,我可以通过删除一个端点来使用http或https.

How can I make it work with HTTP and HTTPS? As of now, I can able to use either http or https by removing one endpoint.

已引用如何设置HTTP和HTTPS WCF 4 RESTful服务?

注意:在IIS中,它是两个网站,一个监听http,另一个监听https.两者在物理文件夹中共享相同的代码

Note: In IIS, it is two web sites one listen on http and another on https. Both sharing same code in physical folder

更新:到目前为止,我删除了端点,它可以正常工作.但是我担心的是删除使用behaviourConfiguration配置的endpoing对我来说不是很好的解决方案.

UPDATE: As of now, I removed endpoints and it works. But my concern is removing endpoing configured with behaviourConfiguration doesnt look great solution to me.

这对http&https

This works for both http & https

  <services>
      <service behaviorConfiguration="MyServiceBehaviour" name="MyService.Lookups">

      </service>
    </services>

推荐答案

我已经重新创建了方案,并使用了web.config为我的测试服务配置了端点.您的配置还可以,并且可以正常工作.对您不起作用的部分可能是您在IIS中配置的https.确保已启用对服务的https访问.如果您使用Visual Studio中的IISExpress对其进行测试,则在项目上单击鼠标左键,然后在属性窗口(视图->属性窗口)中选择SSL Enabled = True.

I've recreated your scenario and used your web.config to configure endpoints for my test service. Your configuration is ok and works correctly. The part that don't works for you is probably your https configuration in IIS. Make sure you have enabled https access to your service. If you test it with IISExpress from Visual Studio then left click on your project and in the properties window (View -> Properties Window ) select for SSL Enabled = True.

这篇关于WebHttpBinding与Http和Https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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