Share via


HttpResponseMessageProperty.SuppressPreamble Propiedad

Definición

Obtiene o establece si se suprime el preámbulo del mensaje.

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

Valor de propiedad

true si se ha suprimido el preámbulo del mensaje; en caso contrario, false.

Comentarios

La SuppressPreamble propiedad permite a los usuarios escribir contenido en desde OutputStream dentro de un cuerpo de la operación WCF. Esto solo surte efecto en escenarios hospedados en web. La SuppressPreamble propiedad es false de forma predeterminada.

Advertencia

Si la SuppressPreamble propiedad se establece trueen , debe establecer los encabezados, el tipo de contenido y el código de estado en la respuesta porque WCF ya no lo hará.

En el código siguiente se muestra un ejemplo de cómo hacerlo.

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

Se aplica a