1

I'm following this post to implement a WCF rest service.

The example works fine until I make a copy of the PlaceOrder method and call it PlaceOrder2, and replace the data type of the order parameter from OrderContract Dictionary. When the method is invoked on the server, the order parameter is empty without any keys.

// Interface
[OperationContract]
[WebInvoke(
    UriTemplate = "/PlaceOrder2",
    RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json,
    Method = "POST"
)]
bool PlaceOrder2(Dictionary<string, string> order);

// Implementation
public bool PlaceOrder2(Dictionary<string, string> order)
{
    Console.WriteLine(order.Keys.Count);    // 0 here
    return true;
}

HTTP Request:

POST [this is not a link]http://localhost:53210/OrderService.svc/PlaceOrder2 HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json; charset=utf-8
Host: localhost:53210
Content-Length: 22

{"test":"12345678"}

HTTP Response:

HTTP/1.1 200 OK
Server: ASP.NET Development Server/11.0.0.0
Date: Tue, 02 Dec 2014 17:24:15 GMT
X-AspNet-Version: 4.0.30319
Content-Length: 4
Cache-Control: private
Content-Type: application/json; charset=utf-8
Connection: Close

true
  • Can you update your question with the code of the copy of the PlaceOrder method? – Faris Zacina Dec 02 '14 at 07:48
  • Can you add the javascript where you post to the WCF service? I just want to see what the post looks like to see if it is valid for the datatype the method is expecting. – Zack Dec 02 '14 at 15:45
  • Also, it might not even be possible to bind JSON data to a Dictionary data type, unless you are using ASP.NET 4.5, and MVC 4. Check out this answer to a related question http://stackoverflow.com/a/4712208/1804496 – Zack Dec 02 '14 at 15:47

0 Answers0