Pinu
Pinu

Reputation: 7510

WebService behind reverse proxy

I have a web service which is behind a reverse proxy like this:

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 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:   mywebservice.comp.com

<?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:   uat.mywebservice.com

<?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>

Upvotes: 7

Views: 5029

Answers (1)

Andrew Terwiel
Andrew Terwiel

Reputation: 709

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

You can do the following:

  1. Create 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 add this to web.config:

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

Upvotes: 4

Related Questions