Export (0) Print
Expand All

WebClientProtocol.RequestEncoding Property

The Encoding used to make the client request to the XML Web service.

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

public function get RequestEncoding () : Encoding 
public function set RequestEncoding (value : Encoding)

Property Value

Type: System.Text.Encoding
The character encoding for the client request. The default is a null reference (Nothing in Visual Basic), which uses the default encoding for the underlying transport and protocol.

The RequestEncoding determines the encoding for the request message. The ContentType of the request will be annotated with the encoding value.

Classes deriving from WebClientProtocol support a particular protocol, such as SoapHttpClientProtocol does for SOAP, set this property to conform to encoding requirements for the specific protocol. For example, the SoapHttpClientProtocol sets the default encoding to UTF-8.

The following example is an ASP.NET Web Form, which calls an XML Web service named Math. Within the EnterBtn_Click function, the Web Form explicitly sets RequestEncoding to UTF-8.

Security noteSecurity 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.

<html>
    <script language="JSCRIPT" runat="server">
        function EnterBtn_Click(src : Object, e : EventArgs){
            var math : MyMath.Math = new MyMath.Math()

            // Set the Content Type to UTF-8.
            math.RequestEncoding = System.Text.Encoding.UTF8

            var iTotal : int = math.Add(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text))
            Total.Text = "Total: " + iTotal.ToString()
        }

    </script>

    <body>
       <form action="MathClient.aspx" runat=server>

          Enter the two numbers you want to add and then press the Total button.
          <p>
          Number 1: <asp:textbox id="Num1" runat=server/>  +
          Number 2: <asp:textbox id="Num2" runat=server/> =
          <asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
          <p>
          <asp:label id="Total"  runat=server/>

       </form>
    </body>
 </html>

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, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

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

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft