views:

496

answers:

3

Hello I'm developing an android application .. which will send location data to a web service to store in the server database.

In Java: I've used this protocol so the URI is: HTTP request instead of REST

HttpPost request = new HttpPost("http://trafficmapsa.com/GService.asmx/GPSdata?   lon="+Lon+"&Lat="+Lat+"&speed="+speed);    

In Asp.net (c#) web service will be:

[WebMethod]
    public CountryName GPSdata(Double Lon, Double Lat, Double speed)
{
String ConnStr = ConfigurationManager.ConnectionStrings["TrafficMapConnectionString"].ConnectionString;
        SqlConnection myConnection = new SqlConnection(ConnStr);
          SqlCommand myCommand = new SqlCommand("INSERT INTO Traffic(Longitude,Latitude,Speed,Distance,Time,MAC_Address) VALUES('" + (@Lon).ToString() + "','" + (@Lat).ToString() + "','" + (@speed).ToString() )", myConnection);


        SqlDataAdapter sadp = new SqlDataAdapter();
        sadp.SelectCommand = myCommand;

        myConnection.Open();
        DataSet DS = new DataSet();


        myCommand.ExecuteNonQuery();


        myConnection.Close();
 

after passing the data from android ..nothing return in back .. and there is no data in the database!! Is there any library missing in the CS file!! I cannot figure out what is the problem.

+1  A: 

Hi, ASFAIK It is not possible to call a .net Web service through REST. Because Web serivce are deployed on SOAP over HTTP. For this kind of requirement, you need to use some third party libraries like KSOAP. Once check this thread

Raghavendra
Technically you are incorrect. Any decent HTTP library could be used to craft SOAP requests. It's a fair amount of work for not much gain, but it could be done. And just to be extra pedantic, there is no such thing as a "REST call".
Darrel Miller
+2  A: 

If you need to have REST use WCF REST instead of ASP.NET web services. There is no REST possibility in ASMX services.

Incognito
what about HTTP request, is the web service above compatible with it?
REST is all about HTTP. Please see overview of WCF REST herehttp://msdn.microsoft.com/en-us/netframework/dd547388.aspx
Incognito
A: 

Perhaps the easiest solution for you would be to enable JSON on the web service. Basically it is just putting some changes in the web config file. Take a look here: http://www.codegain.com/articles/aspnet/howto/prepare-a-json-web-service-and-access-it-with-jquery.aspx . The code samples is for jquery, but it will be really easy to create json object from android.

vucetica