asp.net WebService如何去掉asmx后缀

现在有一个发布好的WebService,地址是http://hovertree.com:2706/UploadExpenseToConstract.asmx
能不能把最后面的asmx去掉呢?变成
http://hovertree.com:2706/UploadExpenseToConstract
但效果和原来的是一样的?

具体代码:
Global.asax

using System;

namespace ExampleHoverTree
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            string hPath= Request.Url.LocalPath.ToString().ToLower();
            if (!hPath.Contains("/hovertreewm.asmx"))
            {
                if (hPath.Contains("/hovertreewm"))
                {
                    Context.RewritePath(hPath.Replace("/hovertreewm", "/hovertreewm.asmx"));
                }
            }
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}

HoverTreeWM.asmx

using System.Web.Services;

namespace ExampleHoverTree.HtExample.HWebMethod
{
    /// <summary>
    /// HoverTreeWM 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://hovertree.top/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 by 何问起
     [System.Web.Script.Services.ScriptService]
    public class HoverTreeWM : System.Web.Services.WebService
    {

        [WebMethod]
        public string HLogin(string hUsername,string hPassword)
        {
           // return hUsername + hPassword;
           return (hUsername.ToLower() == "hewenqi" && hPassword == "HoverTree") ? "登录成功" : "用户名或密码错误";
        }
    }
}

HoverTreeAjax.htm

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>asp.net WebService去掉asmx后缀示例_何问起</title>
    <script src="http://down.hovertree.com/jquery/jquery-1.12.4.min.js"></script>
    <style type="text/css">
        .hovertreelogin {
            height: 400px;
            display: flex;
            justify-content: center;
            align-items: center;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="hovertreelogin">
        <table>
            <tr><td>用户名:</td><td><input type="text" id="husername" /></td><td></td></tr>
            <tr><td>密 码:</td><td><input type="password" id="hpassword" /></td><td></td></tr>
            <tr><td></td><td><input type="button" value="登录" id="hlogin" /></td><td></td></tr>
            <tr><td></td><td><br />正确用户名为:hewenqi<br />密码为HoverTree</td><td></td></tr>
        </table>
    </div>
    <script>
        $(function(){
            $(function () {
                $("#hlogin").on("click", function () {
                    $.ajax({
                        type: ‘Post‘,
                        url: ‘/HtExample/HWebMethod/hovertreeWM/HLogin‘,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: "{‘hUsername‘:‘" + $("#husername").val() + "‘,‘hPassword‘:‘" + $("#hpassword").val() + "‘}",
                        success: function (data, textStatus) {
                            alert(data.d);
                        },
                        error: function (xmlHttpRequest, textStatus, errorThrown) {
                            alert("err " + errorThrown);
                        }
                    });
                })
            })
        })
    </script>
</body>
</html>

效果图:

源码下载:http://hovertree.com/h/bjaf/hv6cqe5n.htm

推荐:http://www.cnblogs.com/sosoft/p/csharpemail.html

时间: 2024-08-05 06:31:56

asp.net WebService如何去掉asmx后缀的相关文章

php soap调用asp.net webservice

原文:php soap调用asp.net webservice 首先做一下准备工作,找到安装环境里的php.ini把;extension=php_soap.dll去掉前面的;.我这里使用的是wamp,php-php扩展里把php_soap启用就可以了. 一.用vs2008新建一个webservice:using System;using System.Linq;using System.Web;using System.Web.Services;using System.Web.Services

在asp.net webservice中如何使用session

原文:在asp.net webservice中如何使用session 原文:刘武|在asp.net webservice中如何使用session 在使用asp.net编写webservice时,默认情况下是不支持session的,但我们可以把WebMethod的EnableSession选项设为true来显式的打开它,请看以下例子: 1 新建网站WebSite 2 新建web服务WebService.asmx,它具有以下两个方法: C#-Code: [WebMethod(EnableSessio

asp.net WebService的一个简单示例

不同的系统之间经常会需要数据的交换对接,而Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的.专门的第三方软件或硬件, 就可相互交换数据或集成.依据Web Service规范实施的应用之间, 无论它们所使用的语言. 平台或内部协议是什么, 都可以相互交换数据.Web Service是自描述. 自包含的可用网络模块, 可以执行具体的业务功能.Web Service也很容易部署, 因为它们基于一些常规的产业标准以及已有的一些技术,诸如标准通用标记语言下的子集XML.HTTP

Jquery利用ajax调用asp.net webservice的各种数据类型(总结篇)

原文:Jquery利用ajax调用asp.net webservice的各种数据类型(总结篇) 老话说的好:好记心不如烂笔头! 本着这原则,我把最近工作中遇到的jquery利用ajax调用web服务的各种数据类型做了一个总结! 本文章没有什么高难度技术,就是记录一下,汇总一下,以便以后需要时查看! 本总结牵涉的数据类型,主要有: string,int这样的基本数据类型 ClassA这样的自定义类 List<ClassA>这样的集合类型 Dictionary这样的字典类型数据 DataSet这样

C# ASP.NET Webservice调用外部exe无效的解决方法

最近用asp.net做webservice,其中有个功能是调用执行外部的exe(类似cmd中执行),但执行Process.Start之后就没有结果,同样代码在winform下正常,折腾两天终于找到解决方法 本文参考了以下网页,十分感谢 http://bbs.csdn.net/topics/300053869 http://blog.163.com/[email protected]/blog/static/15737970200862331842368/ 环境:win7 sp1 64位 以及II

Asp.Net WebService实例

在开始正文之前先给大家推荐一篇详细介绍Asp.net Webservice概念及使用方法的文章,连接是http://blog.csdn.net/zerolsy/article/details/2562146,非常感谢这个博主的分享,学习了. 因工作需求要在现有的Asp.net项目xx报表中实现每天定时导出excel并以邮件形式发送给用户,那么导出excel的方法已经有了,且之前也写了一个Winform项目定时发送邮件的应用程序,那么怎么让Winform应用程序调用Web项目导excel的方法呢?

[WebMethod]的使用,ajax调用[WebMethod]的使用,webservice(web服务) asmx的使用,ajax调用[WebMethod]进行json传输

首先,要分为.net 2.0和.net 3.5这两种情况来考虑 一:.net 2.0情况下 ajax可以调用 aspx.cs 里面加了 [webmethod]的静态方法,而不能调用 asmx 里面加了[webmethod]的方法或者是静态方法 调用aspx.cs里面的webmethod方法的时候,还必须在web.config里面添加如下代码 <httpModules> <add name="ScriptModule" type="System.Web.Han

asp.net WebService+Ajax调用

default.aspx 代码如下: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head run

iOS网络开发-AFNetworking请求asp.net WebService

看到园子有位朋友需要使用AFN框架请求 WebService,所以就整理了一下,demo下载链接在底部 编写WebService可以看这篇博客 http://www.cnblogs.com/linmingjun/p/4606451.html //使用AFN请问无参方法 //使用AFN无参 -(void)AfnDemo { NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://115.2