如何配置一个WCF服务有多个HTTP和HTTPS端点? [英] How to configure a single WCF Service to have multiple HTTP and HTTPS endpoints?

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

问题描述

我所试图做的是得到一个WCF服务的开发环境是HTTP方案,也上班,已经在生产环境中这是HTTPS方案相同的服务工作。如果我删除这两个的Https端点(这些后缀的https),它工作在发展enviornment;同样,如果我只取出了两个HTTP端点然后它工作在生产环境中。我想在web.config中的所有四个端点,如果可能的话。

What I am trying to do is get a SINGLE WCF Service to work in the development environment which is the HTTP scheme, and, also, have the SAME service work in the production environment which is the HTTPS scheme. If I remove the two Https endpoints (those suffixed 'Https'), it works in the development enviornment; likewise, if I remove only the two Http endpoints then it works in the production environment. I would like to have all four endpoints in the web.config, if possible.

我的端点被定义如下:

<endpoint address="/Web" 
        behaviorConfiguration="AjaxBehavior"
        binding="wsHttpBinding" 
        bindingConfiguration="web" 
        name="Web"
        contract="Service" />
<endpoint address="/Custom"
        binding="customBinding" 
        bindingConfiguration="custom" 
        name="Custom"   
        contract="Service" />
<endpoint 
        address="/WebHttps" 
        behaviorConfiguration="AjaxBehavior"
        binding="wsHttpBinding" 
        bindingConfiguration="webHttps" 
        name="WebHttps"
        contract="Service" />
<endpoint address="/CustomHttps"
        binding="customBinding" 
        bindingConfiguration="customHttps" 
        name="CustomHttps" 
        contract="Service" />

编辑:我编辑我的问题,添加错误我收到,并结合部分(下图)。对不起,这个问题的新长度。

Edited: I am editing my question to add the error I am getting, and the binding sections (below). Sorry for the new length of the question.

的错误是: 找不到与绑定的WebHttpBinding端点符合计划http的基址。注册的基址方案是[HTTPS]。

The error is: "Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https]."

此外,生产现场设置为要求SSL。这不能改变。

Additionally, the production site is set up to "Require SSL". That can not change.

该绑定配置:

<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"  />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="AjaxBehavior">
      <enableWebScript/>
    </behavior>
  </endpointBehaviors>
</behaviors>

<bindings>
  <customBinding>
    <binding name="custom">
      <textMessageEncoding>
        <readerQuotas maxDepth="7000000" maxStringContentLength="7000000"
            maxArrayLength="7000000" maxBytesPerRead="7000000"
            maxNameTableCharCount="7000000" />
      </textMessageEncoding>

      <httpTransport maxBufferPoolSize="7000000" maxReceivedMessageSize="7000000"
          maxBufferSize="7000000" />
    </binding>
    <binding name="customHttps">
      <textMessageEncoding>
        <readerQuotas maxDepth="7000000" maxStringContentLength="7000000"
            maxArrayLength="7000000" maxBytesPerRead="7000000"
                  maxNameTableCharCount="7000000" />
      </textMessageEncoding>

      <httpsTransport maxBufferPoolSize="7000000" maxReceivedMessageSize="7000000"
          maxBufferSize="7000000" />

    </binding>
  </customBinding>

  <webHttpBinding>
    <binding name="web"  maxBufferPoolSize="70000000"
        maxReceivedMessageSize="70000000">
      <readerQuotas maxDepth="70000000" maxStringContentLength="70000000"
          maxArrayLength="70000000" maxBytesPerRead="70000000"
          maxNameTableCharCount="70000000" />
      <security mode="None" />
    </binding>

    <binding name="webHttps" maxBufferPoolSize="70000000"
        maxReceivedMessageSize="70000000">

      <readerQuotas maxDepth="70000000" maxStringContentLength="70000000"
                maxArrayLength="70000000" maxBytesPerRead="70000000"
                maxNameTableCharCount="70000000" />

      <security mode="Transport" />
    </binding>
  </webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

任何想法?

推荐答案

请按照下列步骤 -

Follow these steps-

1)写两个端点的服务,一个是http和另一个用于HTTPS。

1) Write two endpoints for the service, one is for http and another for https.

<services>
    <service behaviorConfiguration="MyServiceBehavior" name="JK.MyService">

      <endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="webBinding" contract="JK.IMyService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>

      <endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="webBindingHTTPS" contract="JK.IMyService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>     

    </service>
  </services>

2)同时启用httpGetEnabled =真httpsGetEnabled =在serviceBehaviors真。

2) Enable both httpGetEnabled="True" httpsGetEnabled="true" in serviceBehaviors.

<behaviors>

<serviceBehaviors>      
  <behavior name="MyServiceBehavior">
    <serviceMetadata httpGetEnabled="True" httpsGetEnabled="true"/>
    <serviceDebug includeExceptionDetailInFaults="true" />
  </behavior>      
</serviceBehaviors>

<endpointBehaviors>
  <behavior name="WebBehavior">
    <webHttp/>
  </behavior>
</endpointBehaviors>

</behaviors>

3)写两个绑定配置HTTP和HTTPS。对于HTTP给予安全模式=无和HTTPS给予模式=运输。

3) Write two bindings configurations for http and https. For http give security mode="None" and for https give mode="Transport".

<bindings>
    <webHttpBinding>

      <binding name="webBinding">
        <security mode="None">
          <transport clientCredentialType="None" />
        </security>
      </binding>

      <binding name="webBindingHTTPS">
        <security mode="Transport">
          <transport clientCredentialType="None" />
        </security>
      </binding>

    </webHttpBinding>
  </bindings>

勾选此<一个href="http://jayakrishnagudla.blogspot.com/2009/12/configuring-wcf-services-to-work-with.html">link

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

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