HttpSimpleClientProtocol.Invoke Method (String, String, Object())
Invokes an XML Web service method using HTTP.
Assembly: System.Web.Services (in System.Web.Services.dll)
Protected Function Invoke ( methodName As String, requestUrl As String, parameters As Object() ) As Object
Parameters
- methodName
-
Type:
System.String
The name of the XML Web service method in the derived class that is invoking the Invoke method.
- requestUrl
-
Type:
System.String
The URL of the XML Web service method that the client is requesting.
- parameters
-
Type:
System.Object()
An array of objects containing the parameters to pass to the remote XML Web service. The order of the values in the array corresponds to the order of the parameters in the calling method of the derived class.
Return Value
Type: System.ObjectAn array of objects containing the return value and any by-reference or out parameters of the derived class method.
| Exception | Condition |
|---|---|
| Exception | The request reached the server computer, but was not processed successfully. |
The methodName parameter is used to find the types of the parameters and return values of the method that is invoking the Invoke method. It is also used to find custom attributes which may have been added to the method. HttpMethodAttribute and XmlElementAttribute provide additional information on the derived method that is required for the SOAP protocol.
The following code example is an ASP.NET Web Form, which calls an XML Web service named Math. Within the EnterBtn_Click function, the Web Form synchronously invokes the Add XML Web service method.
<%@ Page Language="VB" %> <html> <script language="VB" runat="server"> Sub EnterBtn_Click(Src As Object, E As EventArgs) Dim math As New Math() ' Call to Add XML Web service method. Dim result As Integer = math.Add(Convert.ToInt32(Num1.Text),Convert.ToInt32(Num2.Text)) Total.Text = "Total: " & result.ToString() End Sub 'EnterBtn_Click </script> <body> <form action="MathClient.aspx" runat=server> Enter the two numbers you want to add and then press the Total button. <p> Number 1: <asp:textbox id="Num1" runat=server/> + Number 2: <asp:textbox id="Num2" runat=server/> = <asp:button text="Total" Onclick="EnterBtn_Click" runat=server/> <p> <asp:label id="Total" runat=server/> </form> </body> </html>
The following code example is a proxy class generated by the Web Services Description Language tool (Wsdl.exe) for the Math XML Web service below. Within the Add method of the proxy class, the Invoke method synchronously invokes the Add Web Service method.
Namespace MyMath <System.Web.Services.WebServiceBindingAttribute(Name:="MathSoap", [Namespace]:="http://tempuri.org/")> _ Public Class Math Inherits System.Web.Services.Protocols.SoapHttpClientProtocol <System.Diagnostics.DebuggerStepThroughAttribute()> _ Public Sub New() MyBase.New Me.Url = "http://www.contoso.com/math.asmx" End Sub <System.Diagnostics.DebuggerStepThroughAttribute(), _ System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/Add", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _ Public Function Add(ByVal num1 As Integer, ByVal num2 As Integer) As Integer Dim results() As Object = Me.Invoke("Add", New Object() {num1, num2}) Return CType(results(0),Integer) End Function <System.Diagnostics.DebuggerStepThroughAttribute()> _ Public Function BeginAdd(ByVal num1 As Integer, ByVal num2 As Integer, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult Return Me.BeginInvoke("Add", New Object() {num1, num2}, callback, asyncState) End Function <System.Diagnostics.DebuggerStepThroughAttribute()> _ Public Function EndAdd(ByVal asyncResult As System.IAsyncResult) As Integer Dim results() As Object = Me.EndInvoke(asyncResult) Return CType(results(0),Integer) End Function End Class End Namespace
The following code example is the Math XML Web service, from which the above proxy class was created.
Available since 1.1