none
Rest Client RRS feed

  • Question

  • The below is my rest contract 

    [OperationContract]
            [WebInvoke(UriTemplate = "Product/open?orderId={orderId}", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
            string OpenProduct(string PId, string OrderId);


    I am using this to invoke this method but I am not able to successfully do it. if it is post method I dont know what is wrong.

    http://www.codeproject.com/Tips/497123/How-to-make-REST-requests-with-Csharp

     var client = new RestClient();
                client.EndPoint = @"http://localhost/Product/open?orderId=123045"; ;
                client.Method = HttpVerb.POST;
                client.ContentType = "application/json";
                client.PostData = "{'PId': 1919}";
                var json = client.MakeRequest();

    I tried many different combination but nothing works if anyone knows what i am doing wrong please let me know any help would be appreciated. thanks


    Chamy07


    • Edited by Chamy07 Wednesday, March 20, 2013 9:31 PM
    Wednesday, March 20, 2013 9:21 PM

All replies

  •  

    var client = new RestClient(); client.EndPoint = @"http://localhost/Product/open"; client.Method = HttpVerb.POST; client.ContentType = "application/json"; var json = client.MakeRequest("?orderId=123045");

    In the Endpoint you are already passing the parameter using ?orderId=123045 then why again you are setting the PostData  = "{'PId': 1919}";



    ViBi

    Thursday, March 21, 2013 9:38 AM
  • You are mistaking my question if you look closely there are two parameters. one is order id and the other one is Pid. I only setting pid. that is where I think I am having trouble

    Chamy07

    Thursday, March 21, 2013 1:33 PM
  • Hi,

    Is there any errors?

    Please check you have define those things correctly in your class and make sure the service is set properly.

    Friday, March 22, 2013 6:12 AM
  • I have written a REST client library which is slightly different to the one you are using. You might want to try it because you can download and debug the source to get more information about what is going wrong:

    RestClient.Net

    NuGet: Install-Package RESTClient.NET



    Saturday, September 3, 2016 1:24 AM