匯出 (0) 列印
全部展開
本主題尚未接受評分 - 為這個主題評分

CreateMessage 方法 (MessageVersion, String, StreamWriterDelegate)

使用指定的版本、動作和委派,從串流建立訊息。

命名空間:  Microsoft.ServiceBus.Web
組件:  Microsoft.ServiceBus (在 Microsoft.ServiceBus.dll 中)
public static Message CreateMessage(
	MessageVersion version,
	string action,
	StreamWriterDelegate writer
)

參數

version
型別:System.ServiceModel.Channels..::..MessageVersion
指定要用於新建立訊息的定址和信封版本。如果使用 REST 提出要求,則定址和信封版本為 None
action
型別:System..::..String
訊息處理方式的描述。若為回應 HTTP 要求而傳送的訊息,此值必須為 "GETRESPONSE"。
writer
型別:Microsoft.ServiceBus.Web..::..StreamWriterDelegate
允許 CreateMessage()()()() 回呼並要求串流填入訊息本文的委派。

傳回值

型別:System.ServiceModel.Channels..::..Message
傳回串流建立的 Message

The following example, pulled from the Image sample in the SDK (as well as the REST Tutorial for Windows Azure Service Bus), uses StreamWriterDelegate to asynchronously stream data into a Message object.

    [ServiceBehavior(Name = "ImageService", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
    class ImageService : ImageContract
    {
        const string imageFileName = "image.jpg";

        Image bitmap;

        public ImageService()
        {
            this.bitmap = Image.FromFile(imageFileName);
        }

        public ImageService(string fname)
        {
            this.bitmap = Image.FromFile(fname);
        }

        public Message GetImage()
        {
            MessageVersion msgVersion = OperationContext.Current.IncomingMessageVersion;

            // Create a StreamWriterDelegate that the StreamMessageHelper
            // will call back on when it needs the data 
            // to write to the message body.
            StreamWriterDelegate swDelegate = new StreamWriterDelegate(this.WriteImage);
            Message response = StreamMessageHelper.CreateMessage(OperationContext.Current.IncomingMessageVersion, "GETRESPONSE", swDelegate);


            HttpResponseMessageProperty responseProperty = new HttpResponseMessageProperty();
            responseProperty.Headers.Add("Content-Type", "image/jpeg");
            response.Properties.Add(HttpResponseMessageProperty.Name, responseProperty);

            return response;
        }

        void WriteImage(Stream stream)
        {
            this.bitmap.Save(stream, ImageFormat.Jpeg);
        }
    }

本文對您有任何幫助嗎?
(剩餘 1500 個字元)
感謝您提供意見

社群新增項目

新增
顯示:
© 2014 Microsoft. 著作權所有,並保留一切權利。