title: Returning bitmap from restful web service
body: <p><strong>Car.cs</strong></p>
  
  <pre><code>[DataContract]
      public class Car
      {
           [DataMember]
           public string Id { get; set; }
           [DataMember]
           public Bitmap Image { get; set; }
      }
  </code></pre>
  
  <p><strong>ICarService.cs</strong></p>
  
  <pre><code>[ServiceContract]
      public interface ICarService
      {
  
          [OperationContract]
          [WebGet(UriTemplate = "Car/{id}")]
  
          Car GetCarId(string id);
      }
  </code></pre>
  
  <p><strong>CarService.svc.cs</strong> </p>
  
  <pre><code>public class CarService : ICarService
      {
  
          public Car GetCarId(string id)
          {
              var newCar = new Car
              {
                  Id = id,
                  Image = new Bitmap("../../Atish.jpg")
              };
              return newCar;
          }
      }
  </code></pre>
  
  <p><strong>web.config</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
  
    &lt;appSettings&gt;
      &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5"/&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service name="CarHaat.CarService"&gt;
          &lt;endpoint address="" behaviorConfiguration="restfulBehavior"
            binding="webHttpBinding" bindingConfiguration="" contract="CarHaat.ICarService" /&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="http://localhost/bookservice" /&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="restfulBehavior"&gt;
            &lt;webHttp /&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name=""&gt;
            &lt;serviceMetadata httpGetEnabled="true" /&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="true" multipleSiteBindingsEnabled="true" /&gt;
    &lt;/system.serviceModel&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
      &lt;!--
          To browse web app root directory during debugging, set the value below to true.
          Set to false before deployment to avoid disclosing web app folder information.
        --&gt;
      &lt;directoryBrowse enabled="true"/&gt;
    &lt;/system.webServer&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Problem is .... when i hit this url localhost:4765/CarService.svc/car/1 in browser, I get following exception. How can i resolve it?? I want to return an image in json format.</p>
  
  <p><img src="https://i.stack.imgur.com/vAI4M.png" alt="enter image description here"></p>