Share via


HttpResponseMessageProperty.SuppressPreamble プロパティ

定義

メッセージ前文を抑制するかどうかを取得または設定します。

public:
 property bool SuppressPreamble { bool get(); void set(bool value); };
public bool SuppressPreamble { get; set; }
member this.SuppressPreamble : bool with get, set
Public Property SuppressPreamble As Boolean

プロパティ値

メッセージの前文を抑制する場合は true。それ以外の場合は false

注釈

プロパティを使用すると、ユーザーは SuppressPreamble WCF 操作本文内から に OutputStream コンテンツを書き込みます。 これは、Web ホスト型のシナリオでのみ有効です。 プロパティはSuppressPreamblefalse既定で です。

警告

プロパティが SuppressPreambletrue設定されている場合は、WCF ではヘッダー、コンテンツ タイプ、状態コードを応答に設定する必要があります。

次のコードは、これを行う方法の例を示しています。

public class Service1 : IService1  
{  
    public void GetData()  
    {  
        HttpContext hc = HttpContext.Current;  
        string str = @"<?xml version=""1.0"" encoding=""utf-8"" ?>";  
        var buffer = new byte[str.Length];  
        buffer = ASCIIEncoding.UTF8.GetBytes(str);  

        // Enable the property.
        var responseProperty = new HttpResponseMessageProperty();  
        responseProperty.SuppressPreamble = true;  
        OperationContext.Current.OutgoingMessageProperties[HttpResponseMessageProperty.Name] = responseProperty;  

        // Set the response.
        hc.Response.StatusCode = 200;  
        hc.Response.ContentType = "text/xml; charset=utf-8";  
        hc.Response.ClearContent();  
        hc.Response.Flush();  

        hc.Response.OutputStream.Write(buffer, 0, buffer.Length);  
        hc.Response.Flush();  
   }  
}  

適用対象