HttpResponseMessageProperty.SuppressPreamble Özellik

Tanım

İletinin önceden derlenip gizlenmeyeceğini alır veya ayarlar.

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

Özellik Değeri

true ileti ön hazırlığının gizlenip gizlenmediğini; aksi takdirde , false.

Açıklamalar

SuppressPreamble özelliği, kullanıcıların bir WCF işlem gövdesi içinden içine içerik OutputStream yazmasına olanak tanır. Bu yalnızca web barındırma senaryolarında etkili olur. SuppressPreamble özelliği varsayılan olarakdırfalse.

Uyarı

SuppressPreamble özelliği olarak trueayarlanırsa, WCF artık bunu yapmayacağından yanıtta üst bilgileri, içerik türünü, durum kodunu ayarlamanız gerekir.

Aşağıdaki kodda bunun nasıl yapıldığını gösteren bir örnek gösterilmektedir.

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

Şunlara uygulanır