7

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>
Matt
  • 25,467
  • 18
  • 120
  • 187
Pinu
  • 7,310
  • 16
  • 53
  • 77
  • This is excatly what my problem is http://blog.graffen.dk/post/Accessing-a-NET-Web-Service-located-behind-a-proxy.aspx I have already tried the solutions suggested here. It works fine with .Net environment. I am not sure how clients on different platform will make it work – Pinu Apr 18 '12 at 19:24
  • I've seen this happen when the reverse proxy sends everything to the root of the application server, not passing the ?wsdl query argument. – JPortillo Sep 11 '20 at 20:01
  • I just thought about something that may help in the web.config. Add your different valid listening addresses to the list in system.serviceModel > serviceHostingEnvironment > baseAddressPrefixFilters. I usually add localhost (to get better error messages when something is wrong) and the actual server URL. It is possible you can add the reverse proxy's URL too. – JPortillo Sep 11 '20 at 20:05
  • well.. first, I think this is an issue that should be raised to the visual studio team. At the moment, I don't have an answer for this scenario or time to look into a solution, but I would consider the possibility of planning\resorting to adding\developing\using an MSBuild project package as an alternative to the web service. Also, I think the issue and\or your intention should be clearer in your title and question. "Incorrect soap address using WebService with reverse proxy endpoint" ... something to that affect – Brett Caswell Sep 12 '20 at 17:46
  • What kind of reverse proxy is it? Is it IIS with URL Rewrite module? Do you have control over the reverse proxy? – Umang Sep 17 '20 at 08:22

1 Answers1

4

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>
    
KyleMit
  • 30,350
  • 66
  • 462
  • 664
Andrew Terwiel
  • 721
  • 4
  • 10
  • thanks for your answer - for some reason I can't get the wsdl to pick up on the reflector when being built. [Here's a sample repo](https://github.com/KyleMit/sample-soap-service) with a brand new wcf project and your changes as mentioned above. I know this is a super old post, but if you can weigh in, I'd be happy to toss some rep your way – KyleMit Sep 11 '20 at 04:07