WebClientProtocol.RequestEncoding プロパティ

定義

クライアントが XML Web サービスを要求するときに使用される Encoding

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

プロパティ値

クライアントによる要求に使用する文字エンコーディング。 既定値は null で、基になるトランスポートとプロトコルに既定のエンコーディングが使用されます。

属性

次の例は、 という名前 Mathの XML Web サービスを呼び出す ASP.NET Web フォームです。 関数内では EnterBtn_Click 、Web フォームによって RequestEncoding が UTF-8 に明示的に設定されます。

重要

この例には、ユーザー入力を受け付けるテキスト ボックスがあります。これにより、セキュリティが脆弱になる可能性があります。 既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。 詳細については、「スクリプトによる攻略の概要」を参照してください。

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

注釈

RequestEncoding 、要求メッセージのエンコードを決定します。 要求の には ContentType エンコード値で注釈が付きます。

から WebClientProtocol 派生したクラスは、SOAP の 場合など SoapHttpClientProtocol 、特定のプロトコルをサポートします。このプロパティは、特定のプロトコルのエンコード要件に準拠するように設定します。 たとえば、 は SoapHttpClientProtocol 既定のエンコードを UTF-8 に設定します。

適用対象

こちらもご覧ください