Export (0) Print
Expand All

HttpResponseMessageProperty.SuppressPreamble Property

.NET Framework 4.6 and 4.5

Gets or sets whether the message preamble is suppressed.

Namespace:  System.ServiceModel.Channels
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public bool SuppressPreamble { get; set; }

Property Value

Type: System.Boolean
true if the message preamble is suppressed; otherwise, false.

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.

Caution noteCaution

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"" ?>";
      byte[] buffer = new byte[str.Length];
      buffer = ASCIIEncoding.UTF8.GetBytes(str);

      // enable the property
      HttpResponseMessageProperty 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.OutputStream.Write(buffer, 0, buffer.Length);

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4
© 2015 Microsoft