HttpResponseMessageProperty.SuppressPreamble Eigenschap

Definitie

Hiermee wordt opgehaald of ingesteld of de prescripte van het bericht wordt onderdrukt.

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

Waarde van eigenschap

true indien de preambule van het bericht wordt onderdrukt; anders, false.

Opmerkingen

Met de SuppressPreamble eigenschap kunnen gebruikers inhoud naar de OutputStream inhoud schrijven vanuit een WCF-bewerkingsbody. Dit geldt alleen voor webhosted scenario's. De SuppressPreamble eigenschap is false standaard.

Waarschuwing

Als de SuppressPreamble eigenschap is ingesteld op true, moet u de headers, het inhoudstype, de statuscode voor het antwoord instellen omdat WCF dit niet meer doet.

In de volgende code ziet u een voorbeeld van hoe u dit doet.

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

Van toepassing op