Exporteren (0) Afdrukken
Alles uitvouwen
EN
Deze inhoud is niet beschikbaar in uw taal, maar wel in het Engels.

StreamMessageHelper.CreateMessage Method (MessageVersion, String, StreamWriterDelegate)

Creates a message from a stream, using the specified version, action, and delegate.

Namespace:  Microsoft.ServiceBus.Web
Assembly:  Microsoft.ServiceBus (in Microsoft.ServiceBus.dll)

public static Message CreateMessage(
	MessageVersion version,
	string action,
	StreamWriterDelegate writer
)

Parameters

version
Type: System.ServiceModel.Channels.MessageVersion
Specifies the Addressing and Envelope versions to use for the newly created message. If the request is made using REST, the Addressing and Envelope version are None.
action
Type: System.String
A description of how the message should be processed. For Messages sent in response to a HTTP request, this value must be “GETRESPONSE”.
writer
Type: Microsoft.ServiceBus.Web.StreamWriterDelegate
A delegate that allows CreateMessage() to callback and ask for a Stream to populate the body of the Message.

Return Value

Type: System.ServiceModel.Channels.Message
Returns a stream-created 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);
        }
    }

Community-inhoud

Toevoegen
Weergeven:
© 2014 Microsoft