Export (0) Print
Expand All

HttpSimpleClientProtocol.Invoke Method

Invokes an XML Web service method using HTTP.

Namespace:  System.Web.Services.Protocols
Assembly:  System.Web.Services (in System.Web.Services.dll)

protected Object Invoke(
	string methodName,
	string requestUrl,
	Object[] parameters
)

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.Object
An array of objects containing the return value and any by-reference or out parameters of the derived class method.

ExceptionCondition
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="C#" %>
<html>
    <script language="C#" runat="server">
       void EnterBtn_Click(Object Src, EventArgs E) 
          {
             Math math = new Math();

         // Call to Add XML Web service method Asynchronously and then wait for it to complete.
         int total = math.Add(Convert.ToInt32(Num1.Text),Convert.ToInt32(Num2.Text));

             Total.Text = "Total: " + total.ToString();
         }

    </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 {
    using System.Diagnostics;
    using System.Xml.Serialization;
    using System;
    using System.Web.Services.Protocols;
    using System.Web.Services;


    [System.Web.Services.WebServiceBindingAttribute(Name="MathSoap", Namespace="http://tempuri.org/")]
    public class Math : System.Web.Services.Protocols.SoapHttpClientProtocol {

        [System.Diagnostics.DebuggerStepThroughAttribute()]
        public Math() {
            this.Url = "http://www.contoso.com/math.asmx";
        }

        [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 int Add(int num1, int num2) {
            object[] results = this.Invoke("Add", new object[] {num1,
                        num2});
            return ((int)(results[0]));
        }

        [System.Diagnostics.DebuggerStepThroughAttribute()]
        public System.IAsyncResult BeginAdd(int num1, int num2, System.AsyncCallback callback, object asyncState) {
            return this.BeginInvoke("Add", new object[] {num1,
                        num2}, callback, asyncState);
        }

        [System.Diagnostics.DebuggerStepThroughAttribute()]
        public int EndAdd(System.IAsyncResult asyncResult) {
            object[] results = this.EndInvoke(asyncResult);
            return ((int)(results[0]));
        }
    }
}

The following code example is the Math XML Web service, from which the above proxy class was created.

<%@ WebService Language="C#" Class="Math"%>
 using System.Web.Services;
 using System;

 public class Math {
      [ WebMethod ]
      public int Add(int num1, int num2) {
          return num1+num2;
          }
 }

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft