none
Pass an object collection to service, using fiddler RRS feed

  • Question

  • I have the string list.

    List<string> _btns = new List<string>();
    _btns.Add("11111111");
    _btns.Add("22222222");
    _btns.Add("33333333");

    Also I have test method

     [TestMethod]
     public void BTNMetadataServiceShouldReturnExpected()
     {
     var client = new RestClient("http://localhost/MoonServices/NumberService.svc/");
    
    var request = new RestRequest("/BTNMetadata/", Method.POST);
    request.AddParameter("BtnsToLookup", JsonConvert.SerializeObject(_btns));

    In my service, I have

     [OperationContract]
            [WebInvoke(Method = "POST", UriTemplate = "/BTNMetadata/", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
    

    I want to use fiddler to test it, but I am not sure how to send the body parameter to the service in the fiddler. Usually fiddler accept plain html parameter. Example.

    In my case the request is a string list, how to play it?


    Friday, April 24, 2015 6:47 PM

Answers

  • HZ.USA,

    For your case, in Fiddler, you can just use ["11111111","22222222","33333333"] in request body. 

    My example is as follows:

    Contract definition:

       [ServiceContract]
        public interface IService1
        {
            [OperationContract]
            [WebInvoke(Method = "POST", UriTemplate = "/BTNMetadata/", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
            List<string> BTNMetadata(List<string> btnsToLookup);
    }

    Implementation:

        public class Service1 : IService1
        {
            public List<string> BTNMetadata(List<string> btnsToLookup)
            {
                return btnsToLookup;
            }
        }

    My service endpoint address is: http://localhost:27557/Service1.svc

    So in Fiddler, I tested this like following, and got response 200.


    Double click on the request, we can see the detailed request and response info.

    Please let me know if you have further question and thanks.

    Thursday, May 7, 2015 4:15 PM

All replies

  • Hi  HZ.USA,

      As per this case, I have shared corresponding details below :

    1. Have you set the Content-Type of the request to application/json in Fiddler's Request body editor?

       If not, goto corresponding Fiddler >> RequestBuilder >> Parsed

       Request-Header :

         Content-Type: application/json;charset=UTF-8

      Request Body:

         [put your JSON string here]

    2.If still not working, then you just remove the forward slash from the url & check it

    For more information, refer the following similar thread :

    http://stackoverflow.com/questions/7273364/wcf-rest-service-post-method-fails-in-fiddler

    Monday, April 27, 2015 5:34 AM
  • I got 404 error. I want the format of my json in the request body.

    Say this one,

    "[\"11111111\",\"22222222\",\"33333333\"]"
    What is the correct format then?

    Monday, April 27, 2015 3:34 PM
  • Hi HZ.USA,
       you can try the below format for json in request body in fiddler:

    keep updated model objects with your data like below
    public class classname
    {
        public string id1 { get; set; }
        public string id2 { get; set; }
        public string id3 { get; set; }
    }

    The json that you pass in Request body:
    {
    "id1":"11111111",
    "id2":"22222222",
    "id3":"33333333"
    }

    Thursday, May 7, 2015 8:53 AM
  • HZ.USA,

    For your case, in Fiddler, you can just use ["11111111","22222222","33333333"] in request body. 

    My example is as follows:

    Contract definition:

       [ServiceContract]
        public interface IService1
        {
            [OperationContract]
            [WebInvoke(Method = "POST", UriTemplate = "/BTNMetadata/", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
            List<string> BTNMetadata(List<string> btnsToLookup);
    }

    Implementation:

        public class Service1 : IService1
        {
            public List<string> BTNMetadata(List<string> btnsToLookup)
            {
                return btnsToLookup;
            }
        }

    My service endpoint address is: http://localhost:27557/Service1.svc

    So in Fiddler, I tested this like following, and got response 200.


    Double click on the request, we can see the detailed request and response info.

    Please let me know if you have further question and thanks.

    Thursday, May 7, 2015 4:15 PM