1

I have a HTTP wcf hosted on IIS. I checked the service on local machine using android emulator. The emulator and wcf on local machine is working fine.

In webbrowser I can access service by using this URL:

 http://localhost:4806/Service1.svc

and in android emulator I am using http://10.0.2.2:4806/Service1.svc to successfully connect android with wcf.

Now I wanted to use android device to access the wcf on PC. How can I do that? Do I need to make any changing in web.config file? it is web.config file code

<service name="JSONService.Service1" behaviorConfiguration="JSONService.Service1Behavior">
  <!-- Service Endpoints -->
  <!--Change the binding to webHttpBinding and set behaviour configuratiion to web-->
  <endpoint address="" binding="webHttpBinding" contract="JSONService.IService1" behaviorConfiguration="web" >
    <!-- 
      Upon deployment, the following identity element should be removed or replaced to reflect the 
      identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
      automatically.
  -->

    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>
  <endpoint address="mex" binding="mexHttpBinding"  contract="IMetadataExchange"/>

</service>

</services>
<behaviors>
    <serviceBehaviors>
        <behavior name="JSONService.Service1Behavior">
            <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
            <serviceMetadata httpGetEnabled="true"/>
            <!-- 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 -->
            <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
    </serviceBehaviors>
    <!--Newly added configuration-->
    <endpointBehaviors>
        <behavior name="web">
            <webHttp/>
        </behavior>
    </endpointBehaviors>
    <!--End of newly added Configuration-->
</behaviors>

Thanks for help.

EDITED:

I tried by using IP of PC like this http://192.168.1.67:4806/Service1.svc and also open a port in windowsfirewall 4806. I wanted to login from android device and get authentication from wcf running on PC. Now when I press login button the application get stop and give error foreclose. Any help is this regard would be great. Thanks

joao2fast4u
  • 6,868
  • 5
  • 28
  • 42
nirmal
  • 31
  • 6
  • Is your Android device part of the same network? Or does it use the internet? – nvoigt Sep 04 '13 at 07:42
  • @nvoigt, I am using internet LAN on pc and wifi on android. My wifi is connect with LAN router. Can I use it without internet as well, if yes then how can I do it. Thanks for reply – nirmal Sep 04 '13 at 09:21
  • host side IP is 192.168.1.67 and on wifi IP is 192.168.1.2. I also try to run service in android phone web browser but wcf is inaccessible. – nirmal Sep 04 '13 at 09:42

1 Answers1

0

In general you do not require any change in the web.config for you to access the service from android client.

And if you think basicHttpBinding would suffice, I guess that will work best for you. You can use normal HTTPPost to continue.

j j
  • 65
  • 1
  • 2
  • 7
  • Check this for link. There you will get some more information. http://stackoverflow.com/questions/669764/how-to-consume-wcf-service-with-android – j j Sep 04 '13 at 07:28
  • I checked it without port as well http://192.168.1.67/Service1.svc, but unable to login. – nirmal Sep 04 '13 at 07:41
  • Can you check the request that is passed on. Since it is web binding, plain REST based request should be generated. Also check if your WCF service actually receives it. Try debugging. – j j Sep 04 '13 at 07:47
  • I'm using wifi on android device and PC is using LAN internet connection. Wcf is in debugging mode but how can I check whether wcf is receiving it or not? – nirmal Sep 04 '13 at 07:52
  • I have to use on real device otherwise its working fine on android emulator but due to no support for bluetooth in emulator I have to test it on real device. I tried emulator in virtualbox to enable bluetooth. It get enabled but as my pc doesn;t have internal bluetooth, I am using bluetooth dongle. but with single dongle I am unable to connect android emulator running in virtual box with wcf running on same pc on HOst xp. do you know any way to to connect host xp with android x86 VM over single dongle. if its possible then it can solve my problem. – nirmal Sep 04 '13 at 08:05
  • I did the same as mentioned here http://stackoverflow.com/questions/13078434/cant-access-wcf-service-hosted-on-iis-remotely-but-can-access-it-locally, I have created a port 4806 in firewall setting and using http://192.168.1.67:4806/Service1.svc in my android client but unable to connect. any idea whats going on wrong? – nirmal Sep 04 '13 at 09:04