Consuming WCF REST Service with multiple parameters WITHOUT DataContract
I need to call my WCF REST Service with multiple parameters with the POST method, but I can’t create DataContract containing my parameters because I need simple types : my webservice will be consumed by an objective C application.
I found this syntax on the MSDN site :
To explain quickly the context, I have to call this method to save a JSON file with the Id passed on a database.
My fisrt question is : is it really possible to pass several parameters to a POST method as shown before ?
Secondly : how can I do to consume my service (in C# for the moment, just to test it) with several parameters ?
I’ve already tested with DataContract, and I was doing like that :
RequestData and ResponseData were declared this way :
But as I said, I can’t do it like this anymore…
I hope I’m enough clear, if not, don’t hesitate to ask me details !
Thanks a lot for your help.
There are a few things you can do to avoid using data contracts. The simplest of them is to use a JSON DOM library which lets you create (and parse) JSON data as a tree, without having to convert them to existing classes. Two of them are the JSON.NET project (used in the sample code below), or the System.Json library (can be downloaded via NuGet). There are many JSON libraries for non-.NET languages as well.
Another thing you can do to make your life simpler is to change the body style of the operation from Wrapped (which wraps the response) to Wrapped to WrappedRequest. The request needs to be wrapped, since you have two inputs, but the response doesn’t, so you can eliminate one step with that.