다음을 통해 공유


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 사용하면 사용자가 WCF 작업 본문 내에서 에서 에 콘텐츠를 OutputStream 쓸 수 있습니다. 이는 webhosted 시나리오에만 적용됩니다. 속성은 SuppressPreamble 기본적으로 입니다 false .

경고

속성이 SuppressPreambletrue설정된 경우 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();
   }
}

적용 대상