title: Return image from WCF web service
body: <p>I have created my first WCF webservice and I am trying to return an image from it based on some passed parameters.  I am getting the error:</p>
  
  <blockquote>
    <p><strong>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.</strong></p>
  </blockquote>
  
  <p>What do I need to do to resolve this issue?</p>
  
  <p>The web.config file of my website that is calling the service has the following config:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
  &lt;bindings&gt;
    &lt;basicHttpBinding&gt;
      &lt;binding name="BasicHttpBinding_IRestImageService" /&gt;
    &lt;/basicHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;client&gt;
    &lt;endpoint address="http://localhost:59473/RestImageService.svc"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRestImageService"
      contract="RestImageService.IRestImageService" name="BasicHttpBinding_IRestImageService" /&gt;
  &lt;/client&gt;
  </code></pre>
  
  <p></p>
  
  <p>
      
        
          
        
      
    </p>
  
  <p>The webservice web.config looks like this:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
  &lt;behaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior&gt;
        &lt;!-- To avoid disclosing metadata information, set the values below to false before deployment --&gt;
        &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/&gt;
        &lt;!-- 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 --&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
      &lt;/behavior&gt;
    &lt;/serviceBehaviors&gt;
  &lt;/behaviors&gt;
  &lt;protocolMapping&gt;
    &lt;add binding="basicHttpsBinding" scheme="https"/&gt;
  &lt;/protocolMapping&gt;
  &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>The Service Contract:</p>
  
  <pre><code>[OperationContract]
      [WebInvoke(Method = "GET",
          ResponseFormat = WebMessageFormat.Json,
          UriTemplate = "Image/{type}/{typeid}/{imageid}/{size}/{extension}",
          RequestFormat = WebMessageFormat.Json,
          BodyStyle = WebMessageBodyStyle.Wrapped)]
      Stream Image(string type, string typeid, string imageid, string size = "lrg", string extension = "jpg");
  </code></pre>
  
  <p>I am very new at WCF, so any help/pointers would be greatly appreciated!</p>
  
  <p><strong>Update</strong>
  After implementing Tim's suggestion, I am getting a new error:</p>
  
  <blockquote>
    <p><strong>There was no endpoint listening at localhost:59473/RestImageService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.</strong></p>
  </blockquote>
  
  <p>I am not sure how to configure the web service to fix this issues.  Any suggestions?</p>
  
  <p>This is how I'm accessing the web service:</p>
  
  <pre><code>RestImageServiceClient client = new RestImageServiceClient();
      client.Image(WSC.Common.BO.User.User.ImageFolder.Buyer, "27085", "BuyerPhoto", "LRG", "jpg");
  </code></pre>
  
  <p>I hope to be able to set the src tag of my image to the web service url once I get it working.</p>