I have a webservice, which I want to POST JSON data. I want to serialize the submitted data into a class and some of the serialized data always returns null.
Here is the problematic part of the json:
"contacts": {
..."1": {
"name": "tesz1",
"phone": "3600000000",
"email": null,
"title": null,
"try_before_reach" : 0
},
"2": {
"name": "tesz1",
"phone": "3600000000",
"email": null,
"title": null,
"try_before_reach" : 0
}
}...
And this is the class :
....
[DataMember(Name = "contacts")]
public Dictionary<string, Contact> contacts { get; set; }
}
[DataContract]
public class Contact
{
[DataMember(Name = "name")]
public string name { get; set; }
[DataMember(Name = "phone")]
public string phone { get; set; }
[DataMember(Name = "email")]
public string email { get; set; }
[DataMember(Name = "title")]
public string title { get; set; }
[DataMember(Name = "try_before_reach")]
public int try_before_reach { get; set; }
}
The webservice:
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/VCC/", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Task<WebhookResponse> ResponseAsync(VCCModel request);
}
And the request.Contact returns with null everytime.
Anyone have any idea what the problem might be?
Thank you very much.
According to the information you provided, I did a test but did not encounter the situation you mentioned. I suspect that there may be an error in your request format or your "request.Contact" is Null.Here is my demo:
Class
webservice
Implementation class
The picture below is the information I got in Postman:
1.You need to check if your request is correct.
2.Check if your "request.Contact" is null.
Feel free to let me know if the problem persists.