Using reflection to call an ASP.NET web service

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

    Although I don't know why Reflection is not working for you there (I assume the compiler might be creating a new class from your [WebService] annotations), here is some advice that might solve your problem:

    Keep your WebService simple, shallow, in short: An implementation of the Facade Pattern.

    Make your service delegate computation to an implementation class, which should easily be callable through Reflection. This way, your WebService class is just a front for your system - you can even add an email handler, XML-RPC frontend etc., since your logic is not coupled to the WebService, but to an actual business layer object.

    Think of WebService classes as UI layer objects in your Architecture.

提交回复
热议问题