ASP.Net Web服务:从WebMethod重定向到另一个Webmethod

时间:2017-12-12 09:43:54

标签: c# asp.net web-services

我在Demo.asmx.cs中编写了以下WebService

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace MyAccount
{
    /// <summary>
    /// Summary description for Demo
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Demo : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld(int hw)
        {
            Server.TransferRequest("Demo.asmx?op=HelloWorld2");
            return "Hello World";
        }
        [WebMethod]
        public string HelloWorld2(int hw)
        {
            return "Hello World2";
        }
    }
}

我期待的输出是来自WebMethod HelloWorld,点击调用,请求转移到HelloWorld2 WebMethod。以下是实际输出:

  1. 浏览Chrome中的Demo.asmx Browse the Demo.asmx in chrome

  2. 单击HelloWorld WebMethod Click the HelloWorld WebMethod

  3. 输入值2并单击Invoke Showing ERR_INVALID_RESPONSE

  4. 预期结果:点击调用后,服务器应将请求转移到HelloWorld2 WebMethod,然后加载HelloWorld2的WebMethod,如: Expected Output

    如何实现这一目标?

    提前致谢

0 个答案:

没有答案