views:

811

answers:

1

I have a WCF service with a method which looks like this (returns null for testing with the debugger, I care only about getting data in for now):

[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "fares", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public List<Fare> GetFares(Dictionary<int, int> itineraries, decimal? threshold, bool includeInternational)
{
    return null;
}

I am trying to make a request to that method using Fiddler, but can't get my head around on what the correct Request Body should be. I could change the Dictionary parameter to something else if that works better.

In Request Headers I pass:

User-Agent: Fiddler
Content-Type: application/json; charset=utf-8

What should I put in the body?

+2  A: 

I think this is what you are after.

{ "itineraries" : [{"Key":1,"Value":2},{"Key":2,"Value":3}], "threshold" : 1.0, "includeInternational" : true }

The dictionary serializes as a Key Value array.

Matthew Pelser
I explicitly set this as POST request in Fiddler, so the data is not sent as part of the URI. The problem is that in Fiddler I want to type the data manually and have no idea how it has to look, so I end up with server side exceptions.
Pawel Krakowiak
Sorry i missread the question and updated my answe. i think the above json is what you are after. If you still get an exception turn system.diagnostics on in the web config if you havent already.
Matthew Pelser
That's it! Thanks.
Pawel Krakowiak