Using reflection to call an ASP.NET web service

前端 未结 8 1441
一向
一向 2021-02-04 17:25

Say I have an ASMX web service, MyService. The service has a method, MyMethod. I could execute MyMethod on the server side as follows:

MyService service = new          


        
8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-04 17:53

    @Radu: I'm able to create an instance and call the method exactly like that. For example, if I have this ASMX:

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService]
    public class MyService : System.Web.Services.WebService
    {
      [WebMethod]
      public string HelloWorld()
      {
        return "Hello World";
      }
    }

    I'm able to call it from an ASPX page's codebehind like this:

    MyService service = new MyService();
    Response.Write(service.HelloWorld());

    Are you saying that shouldn't work?

提交回复
热议问题