title: How to retrieve image using WCF service in Android
body: <p>I'm getting null value in Bitmap decode stream when I try to read values from JSONobject. I do not know where I made mistake. Please try to find my mistake or give alternate solution for my problem. In JSONObject string I am getting the value!.. In DB image value is getting stored as image type and receiving as byte[] in WCF. For more please check the below code.</p>
  
  <p>Android Code:</p>
  
  <pre><code>     protected Bitmap doInBackground(String... params) {
          // TODO Auto-generated method stub
          empID=params[0];
          sendUrl="http://192.168.1.11:5252/RestServiceImpl.svc/signed?empid="+empID;
          try {
              HttpClient httpClient = new DefaultHttpClient();
              HttpGet httpRequest = new HttpGet(sendUrl);
              HttpResponse response = httpClient.execute(httpRequest);
  
              BufferedReader inStream = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
              StringBuffer buffer = new StringBuffer("");
              String line = "";
              String NL = System.getProperty("line.separator");
              while ((line = inStream.readLine()) != null) {
                  buffer.append(line + NL);
  
              }
  
              inStream.close();
              String result = buffer.toString();  
              JSONObject obj = new JSONObject(result);
              //String pageName = obj.getJSONObject("EmployeeID").getString("pageName");
  
              Iterator&lt;?&gt; keys = obj.keys();
  
              while( keys.hasNext() ){
                  String key = (String)keys.next();
                  Object jsonEntity= obj.get(key);
                  String SignatureLink= jsonEntity.toString();
                  String newString = SignatureLink.replace("data:image/png;base64,","");                  
                  //byte[] image= jsonEntity.toString().getBytes();               
                  InputStream stream = new     ByteArrayInputStream(Base64.decode(newString.getBytes(), Base64.DEFAULT));
  
                  Bitmap bitmap = BitmapFactory.decodeStream(stream);// Getting Null Value
  
                  imageView.setImageBitmap(bitmap);
                  //imageView.refreshDrawableState();
                  return bitmap;
          } 
          }
              catch (Exception e) {
              // TODO: handle exception
              return null;
          }
  
          return null;            
      }
  </code></pre>
  
  <p>WCF Interface:</p>
  
  <pre><code>      [OperationContract]
      [WebGet(
          ResponseFormat = WebMessageFormat.Json,
          BodyStyle = WebMessageBodyStyle.Wrapped,
          UriTemplate = "/signed?empid={empid}")]
      byte[] signedornot(string empid);
  </code></pre>
  
  <p>WCF Implementation:</p>
  
  <pre><code>   public byte[] signedornot(string empid) {
  
  
  
          DataSet EmpID = db.ExecuteDataset("select Signature from emp_tb_eob_Employee where EmployeeID=" + Convert.ToInt32( empid));
          byte[] signature= (byte[])EmpID.Tables[0].Rows[0]["Signature"];
          if (signature == null)
          {
              return null;
          }
          else {
              return signature;
          }
  </code></pre>