title: Consuming Restful WCF Service using Android
body: <p>I have been attempting to to connect to a WCF Service from a Android device. I have read a lot of blogs that does not seem to be useful. One of the Operations running on my WCF is </p>
  
  <pre><code>    [OperationContract]
      [WebGet(UriTemplate = "write", ResponseFormat = WebMessageFormat.Json)]
      string write();
  </code></pre>
  
  <p>This writes one entity to a database. When I enter the URL in my phones browser "10.0.0.14/serv/UserManagement.svc/write" I get the relevant message and it writes to the database with no problem. The problem arises when I attempt to Consume the WCF from a android application. I have jumped between many different solution types and I am currently using</p>
  
  <pre><code>try 
  {
  
      DefaultHttpClient httpClient = new DefaultHttpClient();
      URI uri = new URI("http://10.0.0.14/serv/UserManagement.svc/write"); 
  
      HttpGet httpget = new HttpGet(uri);
      httpget.setHeader("Accept", "application/json");
      httpget.setHeader("Content-type", "application/json; charset=utf-8");
  
      HttpResponse response = httpClient.execute(httpget);
      HttpEntity responseEntity = response.getEntity();
  
  
  }
  catch (Exception e) 
  {
       e.printStackTrace();
  }
  </code></pre>
  
  <p>This does not work. I have added <code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;</code> to my manifest. In my LogCat there is a <code>NetworkOnMainThreadException</code>. How can I fix the problem?</p>