title: Connecting to a WCF Service through Android Client
body: <p>I have a very simples Hello World WCF Service, that looks like this:</p>
  
  <pre><code>namespace MyWCFServices
  {
      public class HelloWorldService : IHelloWorldService
      {
  
          public String GetMessage()
          {
              return "Hello world";
          }
  }
  }
  
  namespace MyWCFServices
  {
     [ServiceContract(Namespace = "http://127.0.0.1:49359/GetMessage/")]
      public interface IHelloWorldService
      {
          [OperationContract]
          String GetMessage();
      }
  }
  </code></pre>
  
  <p>My web.config:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;system.web&gt;
      &lt;compilation debug="false" targetFramework="4.0" /&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
    &lt;/system.webServer&gt;
    &lt;system.serviceModel&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="MyServiceTypeBehaviors"&gt;
            &lt;serviceMetadata httpGetEnabled="true" /&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;services&gt;
        &lt;service name="MyWCFServices.HelloWorldService"
               behaviorConfiguration="MyServiceTypeBehaviors"&gt;
  
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="http://127.0.0.1:49359/HostDevServer/HelloWorldService.svc" /&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
  
          &lt;endpoint name="GetMessage" address="" binding="basicHttpBinding"
               contract="MyWCFServices.IHelloWorldService"/&gt;
          &lt;endpoint contract="IMetadataExchange"
             binding="mexHttpBinding" address="mex"/&gt;
        &lt;/service&gt;
      &lt;/services&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>And my android java:</p>
  
  <pre><code>HttpClient httpClient = new DefaultHttpClient(); 
  
          String url = "http://10.0.2.2:49359/HostDevServer/HelloWorldService.svc/GetMessage";
          //String url = "http://10.0.2.2:49359/HostDevServer/HelloWorldService.svc/GetMessage";
          //String url = "http://localhost:49359/HostDevServer/HelloWorldService.svc";
          //String url = "http://localhost:49359/GetMessage";
          try{
  
          HttpGet method = new HttpGet( new URI(url) );
          HttpResponse response = httpClient.execute(method);
          if ( response != null )
          {
              Log.i( "login", "received " + getResponse(response.getEntity()) );
          }
          else
          {
              Log.i( "login", "got a null response" );
          }
  </code></pre>
  
  <p>I'm getting the java.net.SocketException: Permission denied. I already have:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt;
  </code></pre>
  
  <p>So or my WS is not accepting connections or the android client is connecting in wrong way. Probably both. For those who know, in the android client its needed to place 10.0.2.2 to redirect to a localhost web server, so no problem there (at least it works when connecting to a PHP KSOAP WS locally)</p>
  
  <p>Can anyone please guide me?</p>