Using reflection to call an ASP.NET web service

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

    I'm not sure if this would be the best way to go about it. The most obvious way to me, would be to make an HTTP Request, and call the webservice using an actual HTTP GET or POST. Using your method, I'm not entirely sure how you'd set up the data you are sending to the web service. I've added some sample code in VB.Net

    Dim HTTPRequest As HttpWebRequest
    Dim HTTPResponse As HttpWebResponse
    Dim ResponseReader As StreamReader
    Dim URL AS String
    Dim ResponseText As String
    
    URL = "http://www.example.com/MyWebSerivce/MyMethod?arg1=A&arg2=B"
    
    HTTPRequest = HttpWebRequest.Create(URL)
    HTTPRequest.Method = "GET"
    
    HTTPResponse = HTTPRequest.GetResponse()
    
    ResponseReader = New StreamReader(HTTPResponse.GetResponseStream())
    ResponseText = ResponseReader.ReadToEnd()
    

提交回复
热议问题