SoapHttpClientProtocol Class (System.Web.Services.Protocols)

Switch View :
ScriptFree
.NET Framework Class Library
SoapHttpClientProtocol Class

Specifies the class client that proxies derive from when using SOAP.

Inheritance Hierarchy

System.Object
  System.MarshalByRefObject
    System.ComponentModel.Component
      System.Web.Services.Protocols.WebClientProtocol
        System.Web.Services.Protocols.HttpWebClientProtocol
          System.Web.Services.Protocols.SoapHttpClientProtocol

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

Visual Basic
<ComVisibleAttribute(True)> _
Public Class SoapHttpClientProtocol _
	Inherits HttpWebClientProtocol
C#
[ComVisibleAttribute(true)]
public class SoapHttpClientProtocol : HttpWebClientProtocol
Visual C++
[ComVisibleAttribute(true)]
public ref class SoapHttpClientProtocol : public HttpWebClientProtocol
F#
[<ComVisibleAttribute(true)>]
type SoapHttpClientProtocol =  
    class
        inherit HttpWebClientProtocol
    end

The SoapHttpClientProtocol type exposes the following members.

Constructors

  Name Description
Public method SoapHttpClientProtocol Initializes a new instance of the SoapHttpClientProtocol class.
Top
Properties

  Name Description
Public property AllowAutoRedirect Gets or sets whether the client automatically follows server redirects. (Inherited from HttpWebClientProtocol.)
Protected property CanRaiseEvents Gets a value indicating whether the component can raise an event. (Inherited from Component.)
Public property ClientCertificates Gets the collection of client certificates. (Inherited from HttpWebClientProtocol.)
Public property ConnectionGroupName Gets or sets the name of the connection group for the request. (Inherited from WebClientProtocol.)
Public property Container Gets the IContainer that contains the Component. (Inherited from Component.)
Public property CookieContainer Gets or sets the collection of cookies. (Inherited from HttpWebClientProtocol.)
Public property Credentials Gets or sets security credentials for XML Web service client authentication. (Inherited from WebClientProtocol.)
Protected property DesignMode Gets a value that indicates whether the Component is currently in design mode. (Inherited from Component.)
Public property EnableDecompression Gets or sets a Boolean that indicates whether decompression is enabled for this HttpWebClientProtocol. (Inherited from HttpWebClientProtocol.)
Protected property Events Gets the list of event handlers that are attached to this Component. (Inherited from Component.)
Public property PreAuthenticate Gets or sets whether pre-authentication is enabled. (Inherited from WebClientProtocol.)
Public property Proxy Gets or sets proxy information for making an XML Web service request through a firewall. (Inherited from HttpWebClientProtocol.)
Public property RequestEncoding The Encoding used to make the client request to the XML Web service. (Inherited from WebClientProtocol.)
Public property Site Gets or sets the ISite of the Component. (Inherited from Component.)
Public property SoapVersion Gets or sets the version of the SOAP protocol used to make the SOAP request to the XML Web service.
Public property Timeout Indicates the time an XML Web service client waits for the reply to a synchronous XML Web service request to arrive (in milliseconds). (Inherited from WebClientProtocol.)
Public property UnsafeAuthenticatedConnectionSharing Gets or sets a value that indicates whether connection sharing is enabled when the client uses NTLM authentication to connect to the Web server that hosts the XML Web service. (Inherited from HttpWebClientProtocol.)
Public property Url Gets or sets the base URL of the XML Web service the client is requesting. (Inherited from WebClientProtocol.)
Public property UseDefaultCredentials Gets or sets a value that indicates whether to set the Credentials property to the value of the CredentialCache.DefaultCredentials property. (Inherited from WebClientProtocol.)
Public property UserAgent Gets or sets the value for the user agent header that is sent with each request. (Inherited from HttpWebClientProtocol.)
Top
Methods

  Name Description
Public method Abort Cancels a request to an XML Web service method. (Inherited from WebClientProtocol.)
Protected method BeginInvoke Starts an asynchronous invocation of an XML Web service method using SOAP.
Protected method CancelAsync Cancels an asynchronous call to an XML Web service method, unless the call has already completed. (Inherited from HttpWebClientProtocol.)
Public method CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public method Discover Dynamically binds to an XML Web service described in the discovery document at Url.
Public method Dispose() Releases all resources used by the Component. (Inherited from Component.)
Protected method Dispose(Boolean) Releases the unmanaged resources used by the Component and optionally releases the managed resources. (Inherited from Component.)
Protected method EndInvoke Ends an asynchronous invocation of an XML Web service method using SOAP.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection. (Inherited from Component.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method GetReaderForMessage Returns an XmlReader initialized with the Stream property of the SoapClientMessage parameter.
Protected method GetService Returns an object that represents a service provided by the Component or by its Container. (Inherited from Component.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method GetWebRequest Creates a WebRequest for the specified uri. (Overrides HttpWebClientProtocol.GetWebRequest(Uri).)
Protected method GetWebResponse(WebRequest) Returns a response from a synchronous request to an XML Web service method. (Inherited from HttpWebClientProtocol.)
Protected method GetWebResponse(WebRequest, IAsyncResult) Returns a response from an asynchronous request to an XML Web service method. (Inherited from HttpWebClientProtocol.)
Protected method GetWriterForMessage Returns a XmlWriter initialized with the Stream property of the SoapClientMessage parameter.
Public method InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method Invoke Invokes an XML Web service method synchronously using SOAP.
Protected method InvokeAsync(String, Object[], SendOrPostCallback) Invokes the specified method asynchronously.
Protected method InvokeAsync(String, Object[], SendOrPostCallback, Object) Invokes the specified method asynchronously.
Protected method MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public method ToString Returns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from Component.)
Top
Events

  Name Description
Public event Disposed Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)
Top
Remarks

If you are building an XML Web service client, then a proxy class that derives indirectly or directly from WebClientProtocol must be created for the XML Web service. When the XML Web service client calls using SOAP, the proxy class must derive from SoapHttpClientProtocol, which derives from HttpWebClientProtocol. HttpWebClientProtocol, in turn, derives from WebClientProtocol.

To communicate with an XML Web service, create a proxy class that derives indirectly or directly from WebClientProtocol for the XML Web service you want to call. Instead of creating the proxy class manually, use the Web Services Description Language tool (Wsdl.exe) to create a proxy class for a given XML Web service's service description. When a proxy class is generated for the SOAP protocol, synchronous calls to XML Web service methods are made via the Invoke method, whereas asynchronous calls are made using the BeginInvoke method and the EndInvoke method.

Notes to Inheritors

When you override this class, you can introduce methods in the derived class which are specific to a particular type of XML Web service. The methods capture the parameters and call the base class to do the work of communicating with the XML Web service. If the introduced methods are asynchronous, call the BeginInvoke method and the EndInvoke method. If the introduced methods are synchronous, call the Invoke method. The overridden constructor typically sets the Url property to the URL of the XML Web service method.

Examples

The following code example is a proxy class generated by Wsdl.exe for the Math XML Web service. The proxy class derives from SoapHttpClientProtocol, which derives from the abstract WebClientProtocol class.

Visual Basic

Option Strict On
Option Explicit On

Imports System
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



C#


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



Visual C++

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

   };

}



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

Security note Security Note

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

Visual Basic

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


C#

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


Version Information

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

This type is thread safe.

See Also

Reference