Search code examples
asp.netiissoapwsdlwindows-10

IIS/ASP.NET receiving calls from external application to SOAP proxy server


This is a weird one, sorry :( I have a remote server (3rd party, not under my control) that calls a defined endpoint (http://myservice.com/service.asmx), but internally before calling, it appends '.wsdl' to the URL string (so I see http://myservice.com/service.asmx.wsdl) The original server waiting for this request is expecting this, but the original server is no longer in service and I'm hoping to replace it with a 'stub'.

Basically, I'm trying to put an ASP.NET application in place to receive the requests (all currently running locally with IIS). I've used wsdl.exe to create my stub code, and it's called service.asmx. Using POSTMAN against this running service, it all works great - I can debug, see the responses etc, but if I try to rename my project to service.asmx.wsdl to accomodate for the real server making the request, I see a 405 - HTTP Verb error. I've been unable to figure out how to make this work and was thinking it's IIS handers or something like that. I've looked at IIS handers, but I can't seem to find one that would work (i.e., copying the .asmx profiles into newly created .wsdl profiles)

So my question is "Can I make the endpoint at .wsdl behave like it's an .asmx or am I approaching this all wrong?


Solution

  • After much hairpulling, I had to add Global.asax file to my project and implement the following method therein...

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            var path = Request.Path;
            if (path.EndsWith(".asmx.wsdl"))
                Context.RewritePath(path.Replace (".asmx.wsdl", ".asmx"));
    

    This allowed for the default asmx handlers in IIS to remain as-is and process the request from the URL by simply rewriting the URL programmatically.