Click here to Skip to main content
12,455,352 members (61,690 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# WCF
I'm trying to return an image from WCF to a web application, and kept received this error message: The content type image/jpeg of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly.

The web application page calls the WCF to return an image:
srQRCode.QRCodeClient qrCode = new srQRCode.QRCodeClient();
Stream image = qrCode.GetImage();
WCF qrCode.cs
[OperationContract]
[WebInvoke(Method = "GET")]
Stream GetImage();
qrCode.svc.cs
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;
       }
WCF.WebConfig:
<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>

What am I missing here?
Posted 8-Aug-11 10:46am
Updated 8-Aug-11 11:05am
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

This[^] is the best way to research specific error messages.
  Permalink  
Comments
Member 4621605 8-Aug-11 17:27pm
   
I checked the error message but could not find the solution for the problem.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

why not you using image handler class (.ashx file)
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

I'm doing the same thing with QR code and it doesn't work me, can you send me the code if you did it, this is my mail m.alvear@outlook.com thanks Big Grin | :-D
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 14 Feb 2014
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100