Using reflection to call an ASP.NET web service

前端 未结 8 1557
一向
一向 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:49

    I looked back at this question and I think what you're facing is that the ASMX code will be built into a DLL with a random name as part of the dynamic compilation of your site. Your code to look up the type will, by default, only search its own assembly (another App_Code DLL, by the looks of the error you received) and core libraries. You could provide a specific assembly reference "TypeName, AssemblyName" to GetType() but that's not possible in the case of the automatically generated assemblies, which have new names after each recompile.

    Solution.... I haven't done this myself before but I believe that you should be able to use something like this:

    System.Web.Compilation.BuildManager.GetType("MyService", true)
    

    as the BuildManager is aware of the DLLs it has created and knows where to look.

    I guess this really doesn't have to do with Web Services but if it were your own code, Daren's right about Facade patterns.

提交回复
热议问题