HttpSimpleClientProtocol.Invoke(String, String, Object[]) 方法

定义

使用 HTTP 调用 XML Web services 方法。

protected object Invoke (string methodName, string requestUrl, object[] parameters);

参数

methodName
String

正调用 Invoke(String, String, Object[]) 方法的派生类中的 XML Web services 方法的名称。

requestUrl
String

客户端正在请求的 XML Web services 方法的 URL。

parameters
Object[]

一个对象数组,包含要传递到远程 XML Web services 的参数。 数组中值的顺序与派生类的调用方法中的参数顺序对应。

返回

包含派生类方法的返回值、所有引用或 out 参数的对象数组。

例外

请求到达了服务器计算机,但未被成功处理。

示例

下面的代码示例是一个 ASP.NET Web 窗体,它调用名为 的 MathXML Web 服务。 在 EnterBtn_Click 函数中,Web 窗体以同步方式调用 Add XML Web 服务方法。

下面的代码示例是由 Web 服务描述语言工具 (Wsdl.exe) 为 Math 以下 XML Web 服务生成的代理类。 Add在代理类的 方法中Invoke,方法以同步方式调用 Add Web 服务方法。

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]));
        }
    }
}

下面的代码示例是 Math XML Web 服务,从中创建了上述代理类。

<%@ 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;
          }
 }

注解

参数 methodName 用于查找参数的类型,并返回调用 Invoke 方法的方法的值。 它还用于查找可能已添加到 方法的自定义属性。 HttpMethodAttributeXmlElementAttribute 提供有关 SOAP 协议所需的派生方法的其他信息。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1