4

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
  • Can you call your webservice from a browser? If you can't then it looks like a problem with your webservice not accepting REST GET. Commented May 17, 2010 at 18:58

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

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

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

1 Comment

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".
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.