You need to set message body style as wrapped: WebMessageBodyStyle.Wrapped.
Here is an example:
Data model:
public class ServiceResult
{
public string ResultCode { get; set; }
}
public class User
{
public string UserId { get; set; }
public string Name { get; set; }
public string Surename { get; set; }
}
public class Account
{
public string AccNumber { get; set; }
public bool IsActive { get; set; }
}
Service interface method:
[OperationContract]
[WebInvoke(UriTemplate = "user/details", Method = "POST", RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
ServiceResult Details(User user, string key, Account account);
Code to request data:
const string json = @"{
""user"":
{
""UserId"":""12"",
""Name"":""Bogdan"",
""Surename"":""Perecotypole""
},
""key"": ""12345"",
""account"":
{
""AccNumber"":""ED12"",
""IsActive"":""true""
}
}";
Uri uri= new Uri("http://localhost/user/details");
var wc = new WebClient();
wc.Headers["Content-Type"] = "application/json";
var resJson = wc.UploadString(uri, "POST", json);