Edit

Share via


WebClientProtocol.RequestEncoding Property

Definition

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

public:
 property System::Text::Encoding ^ RequestEncoding { System::Text::Encoding ^ get(); void set(System::Text::Encoding ^ value); };
public System.Text.Encoding RequestEncoding { get; set; }
[System.ComponentModel.SettingsBindable(true)]
public System.Text.Encoding RequestEncoding { get; set; }
member this.RequestEncoding : System.Text.Encoding with get, set
[<System.ComponentModel.SettingsBindable(true)>]
member this.RequestEncoding : System.Text.Encoding with get, set
Public Property RequestEncoding As Encoding

Property Value

The character encoding for the client request. The default is null, which uses the default encoding for the underlying transport and protocol.

Attributes

Examples

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.

Important

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="C#" runat="server">
       void EnterBtn_Click(Object Src, EventArgs E) 
          {
             MyMath.Math math = new MyMath.Math();
 
             // Set the Content Type to UTF-8.
             math.RequestEncoding = System.Text.Encoding.UTF8;
            
            int total = math.Add(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text));
            Total.Text = "Total: " + total.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>
<html>
    <script language="VB" runat="server">
        Sub EnterBtn_Click(Src As Object, E As EventArgs)
            Dim math As New MyMath.Math()
            
            ' Set the Content Type to UTF-8.
            math.RequestEncoding = System.Text.Encoding.UTF8
            
            Dim iTotal As Integer = math.Add(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text))
            Total.Text = "Total: " & iTotal.ToString()
        End Sub
 
    </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>

Remarks

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.

Applies to

See also