srQRCode.QRCodeClient qrCode = new srQRCode.QRCodeClient(); Stream image = qrCode.GetImage();
[OperationContract] [WebInvoke(Method = "GET")] Stream GetImage();
public Stream GetImage() { int width = 300; int height = 300; Bitmap bitmap = new Bitmap(width, height); for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { bitmap.SetPixel(i, j, (Math.Abs(i - j) < 2) ? Color.Blue : Color.Yellow); } } MemoryStream ms = new MemoryStream(); bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); ms.Position = 0; WebOperationContext.Current.OutgoingRequest.Headers.Add("Slug", "title"); WebOperationContext.Current.OutgoingRequest.Method = "GET"; WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; return ms; }
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="TransferService" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed" > <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/> <security mode="None"> </security> </binding> </basicHttpBinding> </bindings> <services> <service behaviorConfiguration="wcfQRCode.Service1Behavior" name="wcfQRCode.QRCode"> <endpoint address="" binding="basicHttpBinding" contract="wcfQRCode.IQRCode" bindingConfiguration="TransferService" > <identity> <dns value="localhost"/> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="wcfQRCode.Service1Behavior"> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="true"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="imageBehavior"> <webHttp /> </behavior> </endpointBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)