WCF/WF - Consume Wcf Using REST from Android client

Asked By Niron Kag on 14-Jul-14 12:52 PM

Hi,

My question is about WCF service I wrote in C#, and android client which consume it using “REST” protocol.

I am using example from this link:

http://fszlin.blogspot.com/2010/05/comsuming-wcf-services-with-android.html

I am working with visual studio 2010 .net framework 4.

I wrote a simple WCF service and deployed it to IIS on windows 7.

I succeed to access the service from android (10.0.2.2 is localhost when using android emulator):

http://10.0.2.2/WcfAndroid3/VehicleService.svc

It returns HTML test page with “200 OK”.

 

But when I try to access the function “GetPlates” in the service (or any other function) I get “HTTP/1.1 400 Bad Request”:

http://10.0.2.2/WcfAndroid3/VehicleService.svc/GetPlates

This is my function declaration in my interface:

[OperationContract]   

    [WebGet(     

      UriTemplate = "/GetPlates",

      BodyStyle = WebMessageBodyStyle.WrappedRequest,

      ResponseFormat = WebMessageFormat.Json,

      RequestFormat = WebMessageFormat.Json)]

    IList<string> GetPlates();

 

How can I know if my functions are accessible from "outside" users using “REST” protocol?

I tried a lot, adding and removing function attributes but I still get the error.

I will appreciate any help with this.

Thanks in advance!

Peter Bromberg replied to Niron Kag on 14-Jul-14 12:53 PM

http://10.0.2.2/WcfAndroid3/VehicleService.svc


The range of IP addresses from
10.0.0.0  to 10.255.255.255

Is a private address range and is not visible from the public internet.
Niron Kag replied to Peter Bromberg on 27-Dec-10 04:22 PM

First, thanks for the answer.
Can I do something about this? I think I must use 10.0.2.2 as localhost?
Can I give my Website alias or any other thing I can do?
Thanks again.
Peter Bromberg replied to Niron Kag on 14-Jul-14 12:53 PM
The problem is that your Android (or any other phone) is using its own connectivity to go onto the internet. Since the address you are using is a private class IP address, you are plain out of luck.

www.eggheadcafe.com (72.29.94.50)  on the other hand, is a public internet IP address.
Niron Kag replied to Peter Bromberg on 14-Jul-14 12:54 PM


Hello,

I uploaded my WCF test service to here:

http://www.aaa.gamedroid.biz/VehicleService.svc

Still, I can access the service but not the functions in it, if I call http://www.aaa.gamedroid.biz/VehicleService.svc I receive a test page with 200 ok.

But if I call this http://www.aaa.gamedroid.biz/VehicleService.svc/f3 (f3 is function name in the wcf) I receive status code 400.

I tried a lot and don’t understand what I do wrong:

This is a part of my wcf code:

Intreface:

[OperationContract]
[WebInvoke(

UriTemplate = "f3")]

string f3();

 


Class:
public string f3() {
 return "Hello";
}

 


web.config:
<system.serviceModel>
    <behaviors>
    <endpointBehaviors>
    <behavior name="httpBehavior">
    <webHttp />
    </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
    <behavior name="">
    <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
    </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
    <service name="HttpWcfWeb.VehicleService">
    <endpoint address=""
       behaviorConfiguration="httpBehavior"
       binding="webHttpBinding"
       contract="HttpWcfWeb.IVehicleService" />
    </service>
    </services>
  </system.serviceModel>

 

Is there any problem with my code?
Any help will be appreciated!

geordie replied to Niron Kag on 01-Jul-11 09:08 AM
i am having the same problem.  did you get this working?
Mike Clarke replied to geordie on 14-Jul-14 12:55 PM
I have the same problem to, I have been searching everywhere but can not find an answer. Has anyone got this working?

Please email me if you have mike@fnesse.com