Export (0) Print
Expand All

HttpSimpleClientProtocol Class

Represents the base class for communicating with an XML Web service using the simple HTTP-GET and HTTP-POST protocols bindings.

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

[ComVisibleAttribute(true)]
public ref class HttpSimpleClientProtocol abstract : public HttpWebClientProtocol

This class specifies most of the implementation for communicating with an XML Web service over HTTP using encoders to encode the parameters and return values into common MIME formats. These encoders derive from the MimeFormatter class. By default, a proxy class deriving from HttpSimpleClientProtocol encodes parameters using the application/x-www-form-urlencoded MIME type and the response in plain XML. Custom mime formatters can be specified using the HttpMethodAttribute attribute, however, there is no support for integrating this into a service description and proxy generation.

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

The Web Services Description Language tool (Wsdl.exe) generates derived classes of HttpSimpleClientProtocol for a given Service Description.

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

#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;

public ref class MyMath: public System::Web::Services::Protocols::HttpGetClientProtocol
{
public:

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

   [System::Diagnostics::DebuggerStepThroughAttribute]
   [System::Web::Services::Protocols::HttpMethodAttribute(System::Web::Services::Protocols::XmlReturnReader::typeid,
   System::Web::Services::Protocols::UrlParameterWriter::typeid)]
   [returnvalue:System::Xml::Serialization::XmlRootAttribute("snippet1>",Namespace="http://www.contoso.com/",IsNullable=false)]
   int Add( String^ num1, String^ num2 )
   {
      array<Object^>^temp0 = {num1,num2};
      return  *dynamic_cast<int^>(this->Invoke( "Add", (String::Concat( this->Url, "/Add" )), temp0 ));
   }

   [System::Diagnostics::DebuggerStepThroughAttribute]
   System::IAsyncResult^ BeginAdd( String^ num1, String^ num2, System::AsyncCallback^ callback, Object^ asyncState )
   {
      array<Object^>^temp1 = {num1,num2};
      return this->BeginInvoke( "Add", (String::Concat( this->Url, "/Add" )), temp1, callback, asyncState );
   }

   [System::Diagnostics::DebuggerStepThroughAttribute]
   int EndAdd( System::IAsyncResult^ asyncResult )
   {
      return  *dynamic_cast<int^>(this->EndInvoke( asyncResult ));
   }
};
#using <mscorlib.dll>
#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;


public __gc class MyMath : public System::Web::Services::Protocols::HttpGetClientProtocol {

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

    [System::Diagnostics::DebuggerStepThroughAttribute]
    [System::Web::Services::Protocols::HttpMethodAttribute(__typeof(System::Web::Services::Protocols::XmlReturnReader),
        __typeof(System::Web::Services::Protocols::UrlParameterWriter))]
    [returnvalue: System::Xml::Serialization::XmlRootAttribute(S"int", Namespace=S"http://www.contoso.com/", IsNullable=false)]
    int Add(String* num1, String* num2) {
        Object* temp0 [] = {num1, num2};
        return *dynamic_cast<__box int*>(this->Invoke(S"Add", (String::Concat( this->Url, S"/Add" )), temp0));
    }

    [System::Diagnostics::DebuggerStepThroughAttribute]
    System::IAsyncResult* BeginAdd(String* num1, String* num2, System::AsyncCallback* callback, Object* asyncState) {
        Object* temp1 [] = {num1, num2};
        return this->BeginInvoke(S"Add", (String::Concat( this->Url, S"/Add" )), temp1, callback, asyncState);
    }

    [System::Diagnostics::DebuggerStepThroughAttribute]
    int EndAdd(System::IAsyncResult* asyncResult) {
        return *dynamic_cast<__box int*>(this->EndInvoke(asyncResult));
    }
};

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

#using <System.EnterpriseServices.dll>
#using <System.Web.Services.dll>

using namespace System::Web::Services;
using namespace System;
public ref class Math
{
public:

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

};
#using <mscorlib.dll>
#using <System.EnterpriseServices.dll>
#using <System.Web.Services.dll>
using namespace System::Web::Services;
using namespace System;

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

This type is thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

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

Community Additions

ADD
Show:
© 2014 Microsoft