HttpResponseMessageProperty.SuppressPreamble Eigenschaft

Definition

Ruft ab oder legt fest, ob die Meldungspräambel unterdrückt wird.

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

Eigenschaftswert

Boolean

true, wenn die Meldungspräambel unterdrückt wird, andernfalls false.

Hinweise

Mit der SuppressPreamble Eigenschaft können Benutzer Inhalte aus OutputStream einem WCF-Vorgangstext schreiben. Dies wirkt sich nur auf Webhosted-Szenarien aus. Die SuppressPreamble Eigenschaft ist false standardmäßig vorhanden.

Warnung

Wenn die SuppressPreamble Eigenschaft auf true"" festgelegt ist, müssen Sie die Kopfzeilen, den Inhaltstyp, den Statuscode für die Antwort festlegen, da WCF sie nicht mehr ausführen wird.

Der folgende Code zeigt ein Beispiel für die Vorgehensweise.

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

Gilt für: