WCF http service via https load balancer

你。 提交于 2019-12-05 11:46:22

no, no way to tell the WCF to show the https in WSDL meta data instead of http. our solution is, create both http and https endpointbindings, check if the incoming request is http or https, the incoming request type determine which endpointbindings will be used.

I have had this issue before and the fix pretty much was overriding the SoapExtensionReflector method name: 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
                    }
                }
            }
        }            

    }
    }
}

Once you create the above class into a new or an existing dll project (In my example the dll name is LoadBalancer) you just need to invoke our new extension from the server web config like:

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

If it is under LoadBalancer then it will go ahead and modify the binding location and it will be generate the WSDL with the HTTPS url. Tested on SoapUI and from Visual Studio adding service references (app.config will reflect https). Thanks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!