WCF REST POST of JSON: parameter is empty

Using Fiddler, I send a JSON message to my WCF service. The service uses System.ServiceModel.Activation.WebServiceHostFactory

[OperationContract] [WebInvoke (UriTemplate = "/authenticate", Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest )] String Authorise(String usernamePasswordJson); 

When the POST is done, I can break into the code, but the usernamePasswordJson parameter is null . Why is this?

Note: if I set BodyStyle to Bare , the message will not even get into the code for debugging.

Here's the Fiddler screen: enter image description here

+8
json wcf fiddler
source share
1 answer

You specified your parameter as a String, so it expects a JSON string - and you pass it a JSON object.

To receive this request, you need to have a contract similar to the one below:

 [ServiceContract] public interface IMyInterface { [OperationContract] [WebInvoke(UriTemplate = "/authenticate", Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] String Authorise(UserNamePassword usernamePassword); } [DataContract] public class UserNamePassword { [DataMember] public string UserName { get; set; } [DataMember] public string Password { get; set; } } 
+18
source share

All Articles