1 // Copyright (c) Microsoft Corporation. All rights reserved.
4 using System
.Drawing
.Imaging
;
6 using System
.ServiceModel
;
7 using System
.ServiceModel
.Channels
;
8 using System
.ServiceModel
.Web
;
10 namespace Microsoft
.WebProgrammingModel
.Samples
13 public class ImageGenerationService
17 [WebGet(UriTemplate
= "images")]
18 public Message
GetDynamicImage()
20 string text
= WebOperationContext
.Current
.IncomingRequest
.UriTemplateMatch
.QueryParameters
["text"];
22 Bitmap theBitmap
= GenerateImage(text
);
24 Message response
= StreamMessageHelper
.CreateMessage(MessageVersion
.None
, "", "image/jpeg",
25 delegate(Stream outputStream
)
27 theBitmap
.Save(outputStream
, ImageFormat
.Jpeg
);
34 [WebGet(UriTemplate
= "text")]
35 public Message
GetDynamicText()
37 string text
= WebOperationContext
.Current
.IncomingRequest
.UriTemplateMatch
.QueryParameters
["text"];
38 Message response
= StreamMessageHelper
.CreateMessage(MessageVersion
.None
, "", "text/plain",
42 TextWriter writer
= new StreamWriter(s
);
44 writer
.WriteLine("You said: ");
45 writer
.WriteLine(text
);
46 writer
.WriteLine("Didn't you?");
53 private Bitmap
GenerateImage(string text
)
55 Bitmap bitmap
= new Bitmap(468, 60);
57 Graphics g
= Graphics
.FromImage(bitmap
);
58 Brush brush
= new SolidBrush(Color
.Indigo
);
60 g
.FillRectangle(brush
, 0, 0, 468, 60);
62 brush
= new SolidBrush(Color
.WhiteSmoke
);
63 g
.DrawString(text
, new Font("Consolas", 13), brush
, new PointF(5, 5));