Breyta

Deila með


HttpResponseMessageProperty.SuppressPreamble Property

Definition

Gets or sets whether the message preamble is suppressed.

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

Property Value

true if the message preamble is suppressed; otherwise, false.

Remarks

The SuppressPreamble property enables users to write content into the OutputStream from within a WCF operation body. This takes effect only on webhosted scenarios. The SuppressPreamble property is false by default.

Warning

If the SuppressPreamble property is set to true, you must set the headers, content-type, status code on the response because WCF will no longer do it.

The following code shows an example of how to do this.

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

Applies to