Click here to Skip to main content
13,143,774 members (30,256 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
[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;

        <binding name="TransferService"   maxReceivedMessageSize="2147483647"  maxBufferSize="2147483647" transferMode="Streamed" >
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <security mode="None">
      <service behaviorConfiguration="wcfQRCode.Service1Behavior" name="wcfQRCode.QRCode">
       <endpoint  address="" binding="basicHttpBinding"  contract="wcfQRCode.IQRCode" bindingConfiguration="TransferService"   >
            <dns value="localhost"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <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 name="imageBehavior">
          <webHttp />
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

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

Solution 1

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

Solution 2

why not you using image handler class (.ashx file)
Rate this: bad
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 thanks :D

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 |
Web01 | 2.8.170915.1 | Last Updated 14 Feb 2014
Copyright © CodeProject, 1999-2017
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