Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

StreamWriterDelegate Delegate

This delegate is used by StreamMessageHelper to write the body of streamed messages.

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

public delegate void StreamWriterDelegate(
	Stream output


Type: System.IO.Stream
The stream to write the message body to.

Windows Azure Service Bus supports only Full Trust code access security.

StreamWriterDelegate is used along with StreamMessageHelper to stream data into a Message object. Usually this object is used along with a WebHttpRelayBinding. In turn, this is a common situation when dealing with REST implementations. For more information, see How to: Create a REST-ful Service that Accesses the AppFabric Service Bus.

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 Additions

© 2015 Microsoft