views:

1806

answers:

4

I have written a .NET web Service that is to be consumed by a client outside of my control (my server is a simulator for a live server written in PHP). The web service works as desired but the client does not have the ability to add the .asmx extension, or any extension for that matter, in their calls. They basically use http://localhost/soap/MyWebService while IIS expects http://localhost/soap/MyWebService.asmx. Is there any way to make IIS respond to requests without the .asmx extension?

+4  A: 

Add a wildcard mapping, which will route all requests through ASP.NET:

http://professionalaspnet.com/archive/2007/07/27/Configure-IIS-for-Wildcard-Extensions-in-ASP.NET.aspx

You'll also need to do some URL rewriting, to allow the incoming request http://localhost/soap/MyWebService to map to http://localhost/soap/MyWebService.asmx.

http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

Basically, you could add something like the following to your Application_BeginRequest method:

string path = Request.Path;
if (path.Contains("/soap/") && !path.EndsWith(".asmx"))
    Context.RewritePath(path + ".asmx");

I haven't tested it (and it's a HACK) but it should get you started.

Brannon
While this solution does work it only works on systems running IIS 6 or above.
jercra
It's possible to add a wildcard mapping to IIS 5.x, but the steps are different.
Brannon
Yeah, you can add a wildcard mapping to IIS 5.x but there is a bug when it comes to web service in which you'll get an error about the verb not being allowed. The bug is pretty well noted on the ASP.net message boards.
jercra
+2  A: 

You could also put it in a directory by itself, then in IIS set it as a default document.

On server: C:/mywebsite.com/mywebservice/mywebservice.asmx

In IIS set mywebservice.asmx as a default document

On the web: http://mywebsite.com/mywebservice

Shawn Simon
Tried that and it didn't work.
jercra
A: 

It seems to me that there's something very wrong with the PHP client. They should not be interepreting the URL for the service in any way. Whatever URL is specified in server metadata or client configuration is the URL they should use.

I don't know PHP, but can anyone tell me why it makes any sense for PHP to care how many dots there are in a URL? I can't see that it should matter to any client whether my service is at http://localhost/foo/bar or "http://localhost/foo/b.a.r.asmx?PHP=0".

John Saunders
The issue is not that PHP cares about how many dots there are. It's that the PHP client is not under my control and the address is hardcoded to http://localhost/foo/bar and IIS expects http://localhost/foo/bar.asmx. I needed IIS to understand that requests without .asmx should still be processed.
jercra
This begins to confirm my belief why in the world would it be a good idea for any client of a web service or other resource to hard-code the URL??? URLs change. They should take the URL from some configuration store.
John Saunders
A: 

In php you have to call the wsdl only, you don't need the asxm or that kind of stupid things that .net do.

one simple example

$wsdl = "http://domain/wsdlfile.wsdl"; //url to wsdl 
$client = new SoapClient($wsdl,array('trace' => 1,'encoding' => 'UTF-8','exceptions' => 0)); 
$Return = $client->callfunction();
echo htmlspecialchars($client->__getLastResponse());

that's all.

Pardon me, but not even PHP can call a WSDL. A WSDL simply describes the service that PHP will later call. The WSDL will usually contain the URL of the actual service, which will be the stupid .asmx file.
John Saunders