views:

729

answers:

5

I'm trying to parse a WSDL file which is in another server but has hard codded "localhost" all over the document.

When I fetch it, obviously the program complains "connection refused" because nothing is running in my machine.

My question is: Is it possible to use a webproxy ( such as fiddler ) to redirect those localhost request to my other server so the WSDL references are complete?

:-/

Thanks

p.s. I could always have fixed the remote "wsdl" but the guy on charge will be here until next week and I would like to start working today.

+1  A: 

If you have SSH access to the machine, you should be able to use SSH port forwarding to accomplish this. I'm assuming you're using Windows (based on the C# tag), so you can use Putty as explained here: Using port forwarding with PuTTY. Just follow those instructions to forward the desired port on "localhost" to the server that serves the WSDL.

Alternatively, if you're on a *nix based machine or a Mac, use SSH w/ the following command:

ssh -L PORTYOUWILLUSE:localhost:PORTONSERVER username@serverhostname

For example, if the WSDL were served on port 80, you could do

ssh -L 80:localhost:80 username@server

Once you're logged in (with either method), any requests to localhost on port 80 will be rerouted to the server.

bchang
A: 

If you only want to change it for a few minutes while you parse the WSDL, you might be able to change the HOST file and point "localhost" to the remote IP address. The hosts file is in "C:\Windows\System32\drivers\etc" in Windows VISTA/XP.

Zachary
A: 

There's a few ways you could achieve this, none are particularly robust as long-term solutions, but you mention you just want something temporary until the dev gets back.

If everything after the domain matches (if your remote URL is otherwise the same as the localhost one), you can edit your localhost entry in your hosts file.

In system32\drivers\etc, copy the "hosts" file onto your desktop. Open in notepad and change this line:

127.0.0.1   localhost

Change the IP address (127.0.0.1) to your remote domain. Then copy the hosts file back into the etc directory. (Note: it's not possible to edit this file directly, as Administrator or otherwise).

If you have multiple domains on the remote web service, in IIS, you need to change the web site to serve for requests to "localhost", this might seem a bit odd, but it'll work because your machine will make requests to the server's IP address, but specify the request domain as "localhost". Right-click the website in IIS and select properties, then add the domain "localhost" to the list of HTTP-Header values supported by that web site. You can ignore all of this if your web site in IIS will serve content if you access it via an IP address. If that single IP address is shared between multiple web sites (which is usually the case), you'll get a "Bad hostname" error from IIS as it attempts to look up "localhost" and can't find which web site to direct the request to.

Another possibility is to use a personal proxy server called Proxomitron. It's a little old, and no longer under development, but it's very easy to setup and very solid.

Once you've installed it, open it and click "Config" - change the port it listens on to 80. Next you need to create a redirect rule (it's not actually a redirect, more of a rewrite of the url). You'll need to have a quick read of the docs to understand how to add your own redirect, but there's plenty of samples that ship with the app. The rule you're looking for is RDIR:

$RDIR( ) Is more sneaky and redirects the connection in Proxomitron without telling your browser. This is useful when you want your browser to think it going one place when, in reality, it's going somewhere else.

Matthew Brindley
caveat: if you change "localhost" in your hosts file, you'll start getting all sorts of weird errors, as many applications assume that 127.0.0.1 == localhost
Piskvor
+4  A: 

You could use Fiddler as the proxy from your machine, and then have it rewrite the WSDL to change localhost to the correct machine name.

The FiddlerScript CookBook has an example on how to write this sort of script. Go to that page and search for "Remove all DIV tags (and content inside the DIV tag)". Just change the regex to match localhost and set the replace to the machine name you want to use.

EvilPettingZoo42
+1  A: 

Membrane SOA Monitor/Router is an open source reverse proxy that can rewrite endpoints and schemaLocations in WSDL documents automatically. The host and port used in a request to the router is put into any URL that is used in WSDL and XML Schema documents. See the URL rewriting in the documentation.

baranco