Using reflection to call an ASP.NET web service

前端 未结 8 1416
一向
一向 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 18:00

    Although I cannot tell from your post:

    One thing to keep in mind is that if you use reflection, you need to create an instance of the autogenerated webservice class(the one created from your webservice's WSDL). Do not create the class that is responsbile for the server-side of the service.

    So if you have a webservice

        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [ToolboxItem(false)]
        public class WebService1 : System.Web.Services.WebService
        {
         ...
        }
    

    you cannot reference that assembly in your client and do something like:

    WebService1  ws = new WebService1 ();
    ws.SomeMethod();
    

提交回复
热议问题