Share via


HttpResponseMessageProperty.SuppressPreamble Proprietà

Definizione

Ottiene o imposta un valore che indica se il preambolo del messaggio viene eliminato.

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

Valore della proprietà

true se il preambolo del messaggio viene eliminato; in caso contrario, false.

Commenti

La SuppressPreamble proprietà consente agli utenti di scrivere contenuto nell'interno OutputStream di un corpo dell'operazione WCF. Ciò ha effetto solo sugli scenari webhosted. La SuppressPreamble proprietà è false per impostazione predefinita.

Avviso

Se la SuppressPreamble proprietà è impostata su true, è necessario impostare le intestazioni, il tipo di contenuto, il codice di stato nella risposta perché WCF non lo eseguirà più.

Il codice seguente illustra un esempio di come eseguire questa operazione.

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

Si applica a