The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
HttpResponseMessageProperty::SuppressPreamble Property
.NET Framework (current version)
Gets or sets whether the message preamble is suppressed.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
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"" ?>";
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.ClearContent();
hc.Response.Flush();
hc.Response.OutputStream.Write(buffer, 0, buffer.Length);
hc.Response.Flush();
}
}
.NET Framework
Available since 3.0
Available since 3.0
Show:
