Click here to Skip to main content
15,394,479 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
C#
srQRCode.QRCodeClient qrCode = new srQRCode.QRCodeClient();
Stream image = qrCode.GetImage();

WCF qrCode.cs
C#
[OperationContract]
[WebInvoke(Method = "GET")]
Stream GetImage();

qrCode.svc.cs
C#
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:
HTML
<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
Updated 8-Aug-11 11:05am
v2

This[^] is the best way to research specific error messages.
   
Comments
Member 4621605 8-Aug-11 17:27pm
   
I checked the error message but could not find the solution for the problem.
why not you using image handler class (.ashx file)
   
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 :D
   

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900