简体   繁体   English

带有http和https绑定的WCF Rest Service

[英]WCF Rest Service with both http and https bindings

I'm trying to create a rest service that can accept both http and https traffic. 我正在尝试创建一个可以接受http和https流量的rest服务。 The reason for this is that my company offers our customers both a hosted and non-hosted solution. 原因是我的公司为我们的客户提供托管和非托管解决方案。 In the hosted solution, all traffic goes through an F5 which strips out the SSL and forwards it to our servers in regular http. 在托管解决方案中,所有流量都经过F5,该F5剥离SSL,并将其转发到常规http中的服务器。

The non-hosted solutions have their web servers handle the SSL (thus, the server is expecting https security). 非托管解决方案的Web服务器处理SSL(因此,该服务器具有https安全性)。

The binding was originally defined like so: 绑定最初是这样定义的:

<webHttpBinding>
    <binding closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="64" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None">
      </security>
    </binding>
  </webHttpBinding>

However, this did not work for our non-hosted customers. 但是,这不适用于我们的非托管客户。 I then changed it to this 然后我将其更改为此

   <webHttpBinding>
    <binding closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="64" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
      </security>
    </binding>
  </webHttpBinding>

But, as you can guess, this did not work for our hosted customers. 但是,您可以猜测,这对我们的托管客户不起作用。

Is it possible to have a WCF rest service using the .NET 4.0 framework accept both http and https traffic? 使用.NET 4.0框架的WCF REST服务是否可以接受HTTP和https流量?

I have tried this: 我已经试过了:

      <webHttpBinding>
    <binding name="normalRestBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="64" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
      </security>
    </binding>
    <binding name="secureRestBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="64" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
      </security>
    </binding>
  </webHttpBinding>

with this service definition: 使用此服务定义:

 <service name="theService" behaviorConfiguration="RestServiceBehavior">
    <endpoint name="normalRestEndpoint" address="" behaviorConfiguration="RestEndpoint" binding="webHttpBinding" bindingConfiguration="normalRestBinding" contract="theContract">
      <identity>
        <dns />
      </identity>
    </endpoint>
    <endpoint name="secureRestEndpoint" address="" behaviorConfiguration="RestEndpoint" binding="webHttpBinding" bindingConfiguration="secureRestBinding" contract="theContract">
      <identity>
        <dns />
      </identity>
    </endpoint>
  </service>

Using these, I am now getting this error when trying to access the endpoint over regular http: 使用这些,当尝试通过常规http访问端点时,我现在收到此错误:

Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. 找不到与绑定WebHttpBinding的端点匹配方案https的基地址。 Registered base address schemes are [http]. 注册的基址方案为[http]。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Thanks! 谢谢!

Was able to figure this out. 能够弄清楚这一点。

The code I put toward the bottom of the questions was fine. 我放在问题底部的代码很好。

To resolve that error message, I had to ensure that an https binding existed in IIS on the server(s) I was attempting to use this web config for. 要解决该错误消息,我必须确保在我尝试使用此Web配置的服务器上的IIS中存在https绑定。

Sorry for self-answering, but I didn't want to leave this open and somebody waste their time trying to answer it for me! 抱歉,我无法回答这个问题,但我不想让它公开,有人浪费时间试图为我回答!

Thanks! 谢谢!

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

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