WCF HTTP POST Rest Service with dictionary options

I am working on a WCF recreation service that will have to accept pairs of NAme values. These values ​​are not yet known, so we need to use a common list of pairs of name values.

I tried several methods, but I'm not sure what the best way to do this. I decided that I could access the HttpContext and pull the values ​​from the request body, but I cannot do this.

What is the best way to have a WCF operation that accepts an HTTP message with Name List pairs so that they can be read in an operation similar to how you could pull it out of a request [Key]

+4
source share
1 answer

The parameter would have to create a JSON object to send to the service in a format similar to:

{"kvPairs":[{"Key":"key1","Value":"value1"}, {"Key":"key2","Value":"value2"}]} 

On the service side, configure a method similar to the following:

 [OperationContract] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "")] string DoSomething(Dictionary<string, string> kvPairs); 
+8
source

All Articles