HttpResponseMessageProperty.SuppressPreamble Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
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.
Varoitus
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();
}
}
Tuote | Versiot |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Tuotteen .NET palaute
.NET on avoin lähdekoodi projekti. Anna palautetta valitsemalla linkki: