且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

反向代理背后的WebService

更新时间:2022-06-20 18:30:32

我解决类似问题的方法是强制Web服务发出正确的标头.这是通过以下方式完成的:

What I did to solve a similar problem was to force the webservice to emit the correct headers. This was done by:

  1. 在App_Code文件夹中创建以下类:

  1. creating the following class in the App_Code folder:

using System;
using System.Web.Services.Description;


namespace Msdn.Web.Services.Samples
{
    /// <summary>
    /// Summary description for WSDLReflector
    /// </summary>
    public class WSDLReflector : 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://mywebservice.comp.com", "https://uat.mywebservice.com");
                        }
                    }
                }
            }
        }
    }
}

  • 并将其添加到web.config

  • and adding this to web.config

    <webServices>
        <diagnostics suppressReturningExceptions="true" />
        <soapExtensionReflectorTypes>
            <add type="Msdn.Web.Services.Samples.WSDLReflector,App_Code"/>
        </soapExtensionReflectorTypes>
    </webServices>