Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, November 5, 2018 6:49 AM
Hi Team,
We have WCF service and request in XML format. In the XML request one of the attribute is coming in this format <test/>.
Below are the data member. Its in decimal format and nullable. But with <test/> xml attribute its throwing desensitization error. If we change the xml attribute to <test i:nil="true" /> it works. This issue is only with data type decimal/int/long etc..With data type string <test/> it works well.
[DataMember]
public decimal? test
{ get; set; }
But I need the solution for data type decimal/int/long. Because we are not receiving in this format <test i:nil="true" /> from upstream. They are sending <test />. How to handle this ?
Thanks and regards,
Santosh Hegde
All replies (5)
Monday, November 5, 2018 8:40 AM
Try make it like this and see if it solves your problem (I currently don't have compiler to check).
[DataMember(IsRequired = false)]
public decimal? test { get; set; }
Monday, November 5, 2018 8:53 AM
It doesn't work. Same error: {"There was an error deserializing the object of type. Input string was not in a correct format."}
If I change XML attribute to <test i:nil="true" /> it works.
But as I explained upstream system always send <test />. I need to know how I can deserialize. Is there any way before deserializewe can change the XML attribute to <test i:nil="true" />. But there are multiple xml attributes upstream is sending in this format <test />
Monday, November 5, 2018 9:12 AM
Does this help in deserialization case?
[DataMember(EmitDefaultValue = false)]
Monday, November 5, 2018 9:14 AM
Thank you.
Tried this. Same issue.
Monday, November 5, 2018 10:14 AM
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/data-member-default-values
[DataContract]
public class Employee
{
[DataMember]
public string employeeName = null;
[DataMember]
public int employeeID = 0;
[DataMember(EmitDefaultValue = false)]
public string position = null;
[DataMember(EmitDefaultValue = false)]
public int salary = 0;
[DataMember(EmitDefaultValue = false)]
public int? bonus = null;
[DataMember(EmitDefaultValue = false)]
public int targetSalary = 57800;
}