【问题标题】:WCF http service via https load balancer通过 https 负载平衡器的 WCF http 服务
【发布时间】:2013-11-05 12:29:34
【问题描述】:

我有一个可以通过 http 端点访问的 WCF 网络服务。现在,该服务将通过 https 与负载均衡器一起发布。客户端是通过 svcutil.exe 在 .Net 中创建的,但 Java 客户端也需要 WSDL。

我的理解是:

  • Web 服务在内部是一个 http 服务,无需更改任何内容。地址是 http://myserver.com/example.svc with WSDL ..?wsdl
  • 在外部,该服务必须显示为 https 服务,地址为 https://loadbalancer.com/example.svc 和 WSDL ..?wsdl

从其他帖子中我了解到负载均衡器问题可以通过以下行为配置来解决:

    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <useRequestHeadersForMetadataAddress>
        <defaultPorts>
          <!-- Use your own port numbers -->
          <add scheme="http" port="81" />
          <add scheme="https" port="444" />
        </defaultPorts>
      </useRequestHeadersForMetadataAddress>
    </behavior>

使用此解决方法,我将两个 URL 都解析为服务帮助页面,但调用 https://loadbalancer.com/example.svc 该页面将我带到 http://loadbalancer.com/example.svc?wsdl。当我用 https 替换 http 时,我可以加载 wsdl,但它的所有内部链接都为 http 而不是 https

尝试切换 httpsGetEnabled="true" 导致我遇到很多与 https 相关的问题,我不知道这是否可以帮助我,因为我的服务器本身只知道 http。

所以,我的问题是负载平衡 URL 的 https。我可以告诉 WCF 它应该在 WSDL 元数据中显示 https 而不是 http,我该怎么做?

【问题讨论】:

  • 我用完全不同的方式解决了这个问题:我需要开发环境中的http协议进行调试。在生产和上线前环境中,它必须是 https。这可以在发布过程中完成。当您单击打开配置文件后面的代码时,您会看到几个可用于更改开发配置 XML 文件的文件,这些转换在部署过程中应用到相应配置指定的环境中。

标签: wcf https wsdl load-balancing


【解决方案1】:

我之前遇到过这个问题,修复方法几乎是覆盖 SoapExtensionReflector 方法名称:ReflectDescription。

using System.Web.Services.Description;
namespace LoadBalancer
{
    public class HttpsSoapExtensionReflector : SoapExtensionReflector
    {
        public override void ReflectMethod()
        {
            //no-op
        }

    public override void ReflectDescription()
    {
        ServiceDescription description = ReflectionContext.ServiceDescription; 
        foreach (Service service in description.Services)
        {
            foreach (Port port in service.Ports)
            {
                foreach (ServiceDescriptionFormatExtension extension in port.Extensions)
                {
                    SoapAddressBinding binding = extension as SoapAddressBinding;
                    if (null != binding)
                    {
                        binding.Location = binding.Location.Replace("http://", "https://");//Updating the soap address binding location to use https
                    }
                }
            }
        }            

    }
    }
}

一旦您将上述类创建到新的或现有的 dll 项目中(在我的示例中,dll 名称为 LoadBalancer),您只需从服务器 Web 配置中调用我们的新扩展,例如:

<webServices>
  <soapExtensionReflectorTypes>
    <add type="LoadBalancer.HttpsSoapExtensionReflector, LoadBalancer"/>
  </soapExtensionReflectorTypes>
</webServices>

如果它在 LoadBalancer 下,那么它将继续修改绑定位置,并将生成带有 HTTPS url 的 WSDL。 在 SoapUI 和 Visual Studio 上测试添加服务引用(app.config 将反映 https)。 谢谢

【讨论】:

  • 我的最终解决方案使用了以下技术:link
【解决方案2】:

不,没有办法告诉 WCF 在 WSDL 元数据中显示 https 而不是 http。 我们的解决方案是,同时创建 http 和 https 端点绑定,检查传入请求是 http 还是 https,传入请求类型确定将使用哪些端点绑定。

【讨论】:

    猜你喜欢
    • 2011-09-20
    • 2011-08-04
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 2014-12-11
    相关资源
    最近更新 更多