WebService behind reverse proxy

旧时模样 提交于 2020-01-14 03:20:52

问题


I have a web service which is behind a reverse proxy. Now what is happening is when I try to add a web reference to test the web service then it says that it is unable to download the wsdl file. That is because when the request is sent it it is https://uat.mywebservice.com/Service/Service.asmx but when it hits the reverse proxy and then tires to download the wsdl and disco files it changes the link to http://myservice.comp.com/Service/Service.asmx?wsdl and it this is not the right link as myservice.comp.com is just a name space on reverse proxy. What is happening is headers in the soap file are getting updated to this namespace instead of the actual host name which is uat.mywebservice.com , I was able to see this using fiddler disco file has incorrect address. I had a worked out by creating a proxy class using wsdl.exe tool and then updated all the incorrect links in that class to right host name.

Is there any way that I can make sure the address remains correct when hitting the reverse proxy.

Incorrect:

<?xml version="1.0" encoding="utf-8" ?> 
- <discovery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/disco/"> 
<contractRef ref="http://mvwebservice.comp.com/Service/Service.asmx?wsdl" docRef="http://mvwebservice.comp.com/Service/Service.asmx" xmlns="http://schemas.xmlsoap.org/disco/scl/" /> 
<soap address="http://mywebservice.comp.com/Service/Service.asmx" xmlns:q1="http://tempuri.org/" binding="q1:ServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" /> 
<soap address="http://mywebservice.comp.com/Service/Service.asmx" xmlns:q2="http://tempuri.org/" binding="q2:ServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" /> 
</discovery>

Correct

<?xml version="1.0" encoding="utf-8" ?> 
- <discovery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/disco/"> 
<contractRef ref="https://uat.mvwebservice.com/Service/Service.asmx?wsdl" docRef="https://uat.mvwebservice.com/Service/Service.asmx" xmlns="http://schemas.xmlsoap.org/disco/scl/" /> 
<soap address="https://uat.mywebservice.com/Service/Service.asmx" xmlns:q1="http://tempuri.org/" binding="q1:ServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" /> 
<soap address="https://uat.mywebservice.com/Service/Service.asmx" xmlns:q2="http://tempuri.org/" binding="q2:ServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" /> 
</discovery>

回答1:


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

  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");
                            }
                        }
                    }
                }
            }
        }
    }
    
  2. and adding this to web.config

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


来源:https://stackoverflow.com/questions/10213911/webservice-behind-reverse-proxy

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