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 寫入 。 這隻會對 Webhosted 案例生效。 SuppressPreamble屬性預設為 false

警告

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();  
   }  
}  

適用於