The method call is successful without Request body. When I use below Request body, I get HTTP/1.1 400 Bad Request. Do you see any obvious problem with below requst body?
Request Body
{
"_userConfigData":{"UserName":"bXZpbmphbXVyaQ==", "FirstName":"User1", "LastName":"Last1", "ContactInfo":"None" },
"_configResult": "Miscellaneous"
}
Request Headers
User-Agent: Fiddler
Content-Type: application/json
Host: localhost:1706
Content-Length: 167
Here is the server side method:
[OperationContract]
[WebInvoke(UriTemplate = "UpdateUserDetails/?_clientIP={_clientIP}&AdminName={AdminName}", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
public void UpdateUserDetails(UserConfigData _userConfigData, ConfigResult _configResult, string _clientIP, string AdminName)
{
//
}
Here is the URL that I use with Fiddler2:
http://localhost:1706/WCF/UserConfig/UserConfigService.svc/UpdateUserDetails?_clientIP=localhost&AdminName=admin
Thanks,
I changed my service like the posting above and it did not work until I noticed the first screen shot provided. In the fiddler header is the line
Content-Type: application/json
This allowed me to send data to the service. After changing the return type to string I was able to get raw data back.
I was able to get your code to work, but I had to make some modifications.
Anyway, here is the updated model objects with your data:
public class UserConfigData
{
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string ContactInfo { get; set; }
}
public class Result
{
public UserConfigData UserConfigData { get; set; }
public string ConfigResult { get; set; }
public string ClientIp { get; set; }
public string AdminName { get; set; }
}
The server side method:
[WebInvoke(UriTemplate = "UpdateUserDetails", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
public void UpdateUserDetails(Result result)
{
//
}
The json that you pass in:
{
"AdminName":"String content",
"ClientIp":"String content",
"ConfigResult":"String content",
"UserConfigData":{
"ContactInfo":"String content",
"FirstName":"String content",
"LastName":"String content",
"UserName":"String content"
}
}
UPDATE: Fiddler request screen shot:
And the request gets to the server UpdateUserDetails() Handler:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With