Share via


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

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

Hinweise

Die SuppressPreamble -Eigenschaft ermöglicht Benutzern das Schreiben von Inhalten in einen OutputStream WCF-Vorgangstext. Dies gilt nur für Webhostszenarien. Die SuppressPreamble -Eigenschaft ist false standardmäßig.

Warnung

Wenn die SuppressPreamble -Eigenschaft auf truefestgelegt ist, müssen Sie die Header, den Inhaltstyp, status Code für die Antwort festlegen, da WCF dies nicht mehr tut.

Der folgende Code zeigt ein Beispiel dafür.

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: