Поделиться через


HttpResponseMessageProperty.SuppressPreamble Свойство

Определение

Возвращает или задает, подавляется ли сообщение.

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

Значение свойства

true Значение , если сообщение будет отключено; falseв противном случае .

Комментарии

Свойство SuppressPreamble позволяет пользователям записывать содержимое OutputStream в текст операции WCF. Это действует только в сценариях размещения веб-сайтов. Свойство SuppressPreamble по false умолчанию.

Предупреждение

SuppressPreamble Если для свойства задано trueзначение, необходимо задать заголовки, тип контента, код состояния в ответе, так как WCF больше не сделает это.

В следующем примере кода показано, как это сделать.

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

Применяется к