REST Client in 3.5 - Simple example required

Last post 10-16-2009 5:24 AM by kashifmunir. 2 replies.

Sort Posts:

  • REST Client in 3.5 - Simple example required

    06-22-2009, 11:02 AM
    • Member
      3 point Member
    • kashifmunir
    • Member since 06-14-2006, 1:00 AM
    • Posts 18

    Hi All.

    I am new to ASP.NET 3.5. Havent really had the time to study WCF and its REST capabilities. In one of my projects, I have to communicate to a 3rd party REST based services. I do have the XML structure that I should pass to the REST service and some sample responses that I may receive from the REST based service but I do not know how to do it using .NET 3.5. Can anyone provide a simple example to atleast get me started. Will be really grateful if some code can also be provided in this regard.

     

    Filed under: ,
  • Re: REST Client in 3.5 - Simple example required

    06-24-2009, 8:22 AM

    Here is a way. First install REST Starter Kit Preview 2 and reference your project to Microsoft.Http.dll and Microsoft.Http.Extensions.dll

    using Microsoft.Http;
    
    string baseAddress = "http://exmaple.com/Service.svc/";  // Service Base Address
    string path="exposedUriTemplate";  //the Exposed UriTemplate for your interface
    
    HttpClient client = new HttpClient(baseAddress);
    HttpResponseMessage message = null;
    
    //use HttpContentExtensions to create Http Content, can also use HttpContent class
    HttpContent content=HttpContentExtensions.CreateDataContract<T>(T item);
    
    //do Http Request and get the response
    message = client.Post(path, content);
    //other requests : client.Get(path); client.Put(path, content); client.Delete(path)

    Hope it can help.

    Allen Wang


  • Re: REST Client in 3.5 - Simple example required

    10-16-2009, 5:24 AM
    Answer
    • Member
      3 point Member
    • kashifmunir
    • Member since 06-14-2006, 1:00 AM
    • Posts 18

    Hi Allen,

    Thanks for your response but I did it the easier way. I have used HttpWebRequest and HttpWebResponse to generate requests post it and receive response. This is a far easier way of doing it as it does not require any knowledge of REST starter kit. Although you have to generate the XML request and read the response but it is not that difficult.

Page 1 of 1 (3 items)