共用方式為


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

定義

使用 SOAP 同步叫用 XML Web Service 方法。

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 Service 方法的名稱。

parameters
Object[]

物件陣列,包含要傳遞至 XML Web Service 的參數。 陣列中值的順序會對應至衍生類別之呼叫方法中參數的順序。

傳回

Object[]

物件陣列,包含衍生類別方法的傳回值和任何 referenceout 參數。

例外狀況

要求已到達伺服器電腦,但是並未成功處理。

要求對物件的目前狀態而言無效。

存取往路時發生錯誤。

範例

下列程式碼範例是 XML Web 服務Wsdl.exe Math 所產生的 Proxy 類別。 在 Add Proxy 類別的 方法內 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 建立上述 Proxy 類別的 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 服務建置自己的 Proxy 類別,否則不會直接呼叫 Invoke 方法。

XML Web 服務之 Web 服務描述語言工具 (Wsdl.exe) 所產生的 Proxy 類別會將 XML Web 服務方法公開為 Proxy 類別的名稱。 Proxy 類別會 Invoke 呼叫 方法來叫用 XML Web 服務方法呼叫。 例如,如果 XML Web 服務公開名為 Add 的 XML Web 服務方法,Proxy 類別也會包含名為 Add 的方法。 在 Proxy 類別中方法的程式碼 Add 中,會透過 Invoke 方法對 XML Web 服務方法進行同步呼叫,然後將結果放入 預期的傳回型 Add 別中。

參數 methodName 可用來尋找可能已新增至 方法的自訂屬性,例如 SoapDocumentMethodAttributeSoapDocumentMethodAttribute 提供有關 SOAP 通訊協定所需之衍生方法的其他資訊。

適用於

另請參閱