SoapHttpClientProtocol.Invoke(String, Object[]) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
使用 SOAP 同步调用 XML Web services 方法。
protected:
cli::array <System::Object ^> ^ Invoke(System::String ^ methodName, cli::array <System::Object ^> ^ parameters);
protected:
cli::array <System::Object ^> ^ Invoke(System::String ^ method_name, cli::array <System::Object ^> ^ parameters);
protected object[] Invoke (string methodName, object[] parameters);
protected object[] Invoke (string method_name, object[] parameters);
member this.Invoke : string * obj[] -> obj[]
member this.Invoke : string * obj[] -> obj[]
Protected Function Invoke (methodName As String, parameters As Object()) As Object()
Protected Function Invoke (method_name As String, parameters As Object()) As Object()
参数
- methodNamemethod_name
- String
XML Web services 方法的名称。
- parameters
- Object[]
包含要传递给 XML Web services 的参数的对象数组。 数组中值的顺序与派生类的调用方法中的参数顺序对应。
返回
- Object[]
包含派生类方法的返回值、所有 reference
或 out
参数的对象数组。
例外
请求到达了服务器计算机,但未被成功处理。
请求对对象的当前状态无效。
访问网络时出错。
示例
下面的代码示例是由 XML Web 服务Wsdl.exe Math
生成的代理类。 在 Add
代理类的方法中,该方法 Invoke 调用 Add
XML Web 服务方法。
#using <System.Web.Services.dll>
#using <System.Xml.dll>
#using <System.dll>
using namespace System::Diagnostics;
using namespace System::Xml::Serialization;
using namespace System;
using namespace System::Web::Services::Protocols;
using namespace System::Web::Services;
namespace MyMath
{
[System::Web::Services::WebServiceBindingAttribute(Name="MyMathSoap",Namespace="http://www.contoso.com/")]
public ref class MyMath: public System::Web::Services::Protocols::SoapHttpClientProtocol
{
public:
[System::Diagnostics::DebuggerStepThroughAttribute]
MyMath()
{
this->Url = "http://www.contoso.com/math.asmx";
}
[System::Diagnostics::DebuggerStepThroughAttribute]
[System::Web::Services::Protocols::SoapDocumentMethodAttribute("http://www.contoso.com/Add",
RequestNamespace="http://www.contoso.com/",ResponseNamespace="http://www.contoso.com/",
Use=System::Web::Services::Description::SoapBindingUse::Literal,
ParameterStyle=System::Web::Services::Protocols::SoapParameterStyle::Wrapped)]
int Add( int num1, int num2 )
{
array<Object^>^temp0 = {num1,num2};
array<Object^>^results = this->Invoke( "Add", temp0 );
return *dynamic_cast<int^>(results[ 0 ]);
}
[System::Diagnostics::DebuggerStepThroughAttribute]
System::IAsyncResult^ BeginAdd( int num1, int num2, System::AsyncCallback^ callback, Object^ asyncState )
{
array<Object^>^temp1 = {num1,num2};
return this->BeginInvoke( "Add", temp1, callback, asyncState );
}
[System::Diagnostics::DebuggerStepThroughAttribute]
int EndAdd( System::IAsyncResult^ asyncResult )
{
array<Object^>^results = this->EndInvoke( asyncResult );
return *dynamic_cast<int^>(results[ 0 ]);
}
};
}
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="MyMathSoap", Namespace="http://www.contoso.com/")]
public class MyMath : System.Web.Services.Protocols.SoapHttpClientProtocol {
[System.Diagnostics.DebuggerStepThroughAttribute()]
public MyMath() {
this.Url = "http://www.contoso.com/math.asmx";
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.contoso.com/Add", RequestNamespace="http://www.contoso.com/", ResponseNamespace="http://www.contoso.com/", 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]));
}
}
}
Option Strict On
Option Explicit On
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization
Namespace MyMath
<System.Web.Services.WebServiceBindingAttribute(Name:="MyMathSoap", [Namespace]:="http://www.contoso.com/")> _
Public Class MyMath
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://www.contoso.com/Add", RequestNamespace:="http://www.contoso.com/", ResponseNamespace:="http://www.contoso.com/", 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
下面的代码示例是 Math
创建上述代理类的 XML Web 服务。
<%@ WebService Language="C#" Class="MyMath"%>
using System.Web.Services;
using System;
[WebService(Namespace="http://www.contoso.com/")]
public class MyMath {
[ WebMethod ]
public int Add(int num1, int num2) {
return num1+num2;
}
}
<%@ WebService Language="VB" Class="MyMath"%>
Imports System.Web.Services
Imports System
<WebService(Namespace:="http://www.contoso.com/")> _
Public Class MyMath
<WebMethod()> _
Public Function Add(num1 As Integer, num2 As Integer) As Integer
Return num1 + num2
End Function 'Add
End Class 'Math
注解
通常,除非为 XML Web 服务生成自己的代理类,否则不会直接调用 Invoke 该方法。
由 XML Web 服务描述语言工具 (Wsdl.exe) 生成的代理类将 XML Web 服务方法公开为代理类的名称。 代理类调用 Invoke 该方法以调用 XML Web 服务方法调用。 例如,如果 XML Web 服务公开名为 Add
XML Web 服务方法,则代理类还包含一个名为 Add
的方法。 在代理类中方法的代码 Add
中,通过 Invoke 该方法对 XML Web 服务方法进行同步调用,然后将结果放入预期的返回类型 Add
中。
该 methodName
参数用于查找可能已添加到方法的自定义属性,例如 SoapDocumentMethodAttribute。 SoapDocumentMethodAttribute 提供有关 SOAP 协议所需的派生方法的其他信息。