HttpResponseMessageProperty.SuppressPreamble 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置是否禁止发送消息前导码。
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 写入。 这仅适用于 Web 托管方案。 The SuppressPreamble property is false
by default.
警告
如果属性 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();
}
}