通过https负载平衡器的WCF http服务
我有一个可以通过http端点访问的WCF Web服务。现在,该服务应通过https使用负载平衡器发布。客户端是通过svcutil.exe在.Net中创建的,但Java客户端也需要WSDL 我的理解是:通过https负载平衡器的WCF http服务,wcf,https,wsdl,load-balancing,Wcf,Https,Wsdl,Load Balancing,我有一个可以通过http端点访问的WCF Web服务。现在,该服务应通过https使用负载平衡器发布。客户端是通过svcutil.exe在.Net中创建的,但Java客户端也需要WSDL 我的理解是: 在内部,webservice是一个http服务,不需要任何更改。地址是http://myserver.com/example.svc with WSDL..?WSDL 从外部来看,该服务必须显示为https服务,地址为httpshttps://loadbalancer.com/example.s
- 在内部,webservice是一个http服务,不需要任何更改。地址是http://myserver.com/example.svc with WSDL..?WSDL
- 从外部来看,该服务必须显示为https服务,地址为httpshttps://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吗?我该怎么做?不,没有办法告诉WCF在WSDL元数据中显示https而不是http。
我们的解决方案是,创建http和https端点绑定,检查传入请求是http还是https,传入请求类型确定将使用哪些端点绑定。我以前遇到过这个问题,修复程序几乎覆盖了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)。
谢谢我以完全不同的方式解决了这个问题:我需要在开发环境中使用http协议进行调试。在生产和预调试环境中,必须使用https。这可以在发布过程中完成。当您单击打开配置文件的代码隐藏时,您会看到几个可用于更改开发配置XML文件的文件,这些转换将在部署过程中应用到相应配置指定的环境中。我的最终解决方案使用了以下技术: