Language

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 ホストされたシナリオでのみ有効になります。 既定では、 SuppressPreamble プロパティは false 。

Warning

SuppressPreamble プロパティが true に設定されている場合は、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();
   }
}

適用対象