调用不带 .asmx 扩​​展名的 IIS Web 服务 [英] Call an IIS Web Service without the .asmx extension

查看:22
本文介绍了调用不带 .asmx 扩​​展名的 IIS Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 .NET Web 服务,供我控制之外的客户端使用(我的服务器是用 PHP 编写的实时服务器的模拟器).Web 服务按需要工作,但客户端无法在其调用中添加 .asmx 扩​​展名或任何与此相关的扩展名.他们基本上使用 http://localhost/soap/MyWebService 而 IIS 需要 http://localhost/soap/MyWebService.asmx.有没有办法让 IIS 在没有 .asmx 扩​​展名的情况下响应请求?

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?

推荐答案

添加通配符映射,它将通过 ASP.NET 路由所有请求:

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

您还需要进行一些 URL 重写,以允许传入请求 http://localhost/soap/MyWebService 映射到 http://localhost/soap/MyWebService.asmx.

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

基本上,您可以在 Application_BeginRequest 方法中添加类似以下内容:

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");

我还没有测试过它(它是一个 HACK),但它应该让你开始.

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

这篇关于调用不带 .asmx 扩​​展名的 IIS Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆