使用http和https绑定/端点部署WCF服务 [英] Deploying WCF Service with both http and https bindings/endpoints

查看:230
本文介绍了使用http和https绑定/端点部署WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个WCF Web服务供Silverlight应用程序使用。最初,该服务仅需要基本的http绑定。我们现在需要能够部署服务以在http和https下使用。我找到了web.config的一些设置,允许我这样做:

I've written a WCF web service for consumption by a Silverlight app. Initially, the service only required a basic http binding. We now need to be able to deploy the service for use under both http and https. I've found some settings for web.config that allow me to do this as follows:

<system.serviceModel>
  <behaviors>
    <endpointBehaviors>
      <behavior name="SilverlightFaultBehavior">
        <silverlightFaults />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="CxtMappingWebService.CxtMappingWebServiceBehavior">
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="True" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <bindings>
    <basicHttpBinding>
      <binding name="SecureHttpBinding">
        <security mode="Transport" />
      </binding>
      <binding name="BasicHttpBinding">
        <security mode="None" />
      </binding>
    </basicHttpBinding>
  </bindings>
  <services>
    <service name="CxtMappingWebService.CxtMappingWebService" behaviorConfiguration="CxtMappingWebService.CxtMappingWebServiceBehavior">
      <endpoint address="" bindingConfiguration="SecureHttpBinding" binding="basicHttpBinding" contract="CxtMappingWebService.ICxtMappingWebService" behaviorConfiguration="SilverlightFaultBehavior" />
      <endpoint address="" bindingConfiguration="BasicHttpBinding" binding="basicHttpBinding" contract="CxtMappingWebService.ICxtMappingWebService" behaviorConfiguration="SilverlightFaultBehavior" />
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
  </services>
</system.serviceModel>

不幸的是,这有问题。

Unfortunately, however, there's a problem with this.

此Web服务需要部署到我们客户的数百台服务器上,并非所有服务器都使用https。将其部署到未在IIS中设置https绑定的服务器会导致其失败。如果在IIS中没有设置https绑定,是否有办法在web.config中默认使用这两个绑定而不会死亡?

This web service needs to be deployed to hundreds of our customers' servers, and not all of them will be using https. Deploying it to a server that doesn't have an https binding set up in IIS causes it to fail. Is there a way to have both of these bindings in the web.config by default without it dying if there's not an https binding set up in IIS?

我们已经找到了解决此问题的可能方案,但它并不适合我们的部署要求。

We've got a possible solution for this problem, but it doesn't really fit well with our deployment requirements.

之前有没有其他人遇到这样的事情,你是如何解决的?

Has anybody else encountered anything like this before, and how did you resolve it?

推荐答案

如果您不使用安装程序,则此页面上接受的答案没什么用处。
正确的答案在于OP自己稍后编辑,所有人需要做的是绑定IIS中的http和https端口,然后使用下面的配置。

The accepted answer on this page is not of much use if you don't use an installer. The correct answer lies in a later edit by the OP himself, all one needs to do is bind both http and https ports in IIS and then use the configuration below.

            <service name="CxtMappingWebService.CxtMappingWebService" behaviorConfiguration="CxtMappingWebService.CxtMappingWebServiceBehavior">
              <endpoint address="" bindingConfiguration="SecureHttpBinding" binding="basicHttpBinding" contract="CxtMappingWebService.ICxtMappingWebService" behaviorConfiguration="SilverlightFaultBehavior" />
              <endpoint address="" bindingConfiguration="BasicHttpBinding" binding="basicHttpBinding" contract="CxtMappingWebService.ICxtMappingWebService" behaviorConfiguration="SilverlightFaultBehavior" />
              <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>

这对我来说还算不错!

这篇关于使用http和https绑定/端点部署WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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