Cannot transfer JSON Post data to WCF REST service using Fiddler

I am trying to call the WCF service as shown below:

[WebInvoke(UriTemplate = "Login", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public string Process(string AuthenticationInfo)
{

I am trying to call it using the following in Fiddler 2:

User-Agent: Fiddler
Host: localhost
content-type: application/json;charset=utf-8
content-length: 0
data: {"AuthenticationInfo": "data"}

I have a breakpoint in the method and it hits the breakpoint, but the value for AuthenticationInfo is always null, not "data".

What am I doing wrong?

Thank.

+3
source share
3 answers

By default, the "body style" of the attribute is [WebInvoke]"Bare", which means that the input (in your case "data") should be sent "as is". What you send is a wrapped version of the input (i.e., wrapped in an object whose key is the name of the parameter.

: WebInvoke, BodyStyle:

[WebInvoke(
    UriTemplate = "Login", 
    RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public string Process(string AuthenticationInfo)   

"":

POST .../Login HTTP/1.1
User-Agent: Fiddler
Host: localhost
Content-Type: application/json;charset=utf-8
Content-Length: 6

"data"
+3

HTTP POST Fiddler? WCF REST POST, , Method="GET" WebInvoke. , , GET , , POST Fiddler.

+1

You send Content-Length as 0, but it should be the length of your POST data.

0
source

All Articles