0

I have successfully created my app and now want to connect it to a localhost to check the working of my app. I have been suggested to use restsharp for connecting to the server using php and json to receive data from server.

I have looked at codes for both but do not completely understand how the process works. I have looked into all forums but found could snippets with no explanation as how it works. I have even tried restsharp.org and google search results. Please explain me as to how this works.

nik
  • 576
  • 2
  • 7
  • 14
  • In other words, you need an example of how to connect to a RESTful service on a windows phone 7 applications, preferably using the RestSharp client library wrapper? By the way, the HTTPClient portable class libraries can do this now seamlessly, unless there are specific features of restsharp you wish to use. – FunksMaName Jul 24 '13 at 09:25

1 Answers1

0

RestSharp is a library that helps you invoking REST web services.
You use RestSharp on your client to invoke Rest style Web Services (send and receive data) Here is an example on the usage of your service:
var client = new RestClient(baseUrl);

var request = new RestRequest("/*rest_resource*/", Method.POST);
// see Rest services

// set the request format - HTTP Content-Type text/xml
request.RequestFormat = DataFormat.Xml;

// add data to the request
request.AddBody("<books><book>RestSharp Book</book></books>");

/* send the request and if your service returns text put the as expected return type; otherwise you will get raw byte array*/
IRestResponse response = client.Execute(request);

//HTTP status code 200-success
Assert.IsTrue(response.StatusCode == HttpStatusCode.OK);
Assert.IsTrue(!string.IsNullOrEmpty(response.Data)); // the response is not empty

sundog
  • 179
  • 6
  • I also want to use Json when i receive data from the server. Json is needed by me to differentiate the data received by the server and place it in the textbox's required. How do i go about that? – nik Jul 24 '13 at 18:06
  • The sample code above shows you how to invoke a Rest web service using RestSharp. In other words how you receive data from server. RestSharp also provides functionality for sending and reciving data in Json format. Check this [thread](http://stackoverflow.com/questions/16156738/restsharp-deserialization-with-json-array) as example of json with restsharp. – sundog Jul 25 '13 at 09:04