0

This my web service request:

[System.Xml.Serialization.XmlElementAttribute("Duration", typeof(string), DataType="duration", Order=1)]
[System.Xml.Serialization.XmlElementAttribute("EndDate", typeof(System.DateTime), Order=1)]
public object Item {
    get { return this.itemField; }
    set { this.itemField = value; }
}

How to set the value EndDate and Duration from the object.

Just now i just set like below:

dateRange.Item = DateTime.now

From above code onli set the EndDate and how to set the value from duration.

  • 1
    Why did you use `{ }` - what was the intent there? Are you trying to make it `null`, perhaps? – ADyson Oct 01 '20 at 09:28
  • 1
    You need to create an xml node and assign its attributes. Honestly, you better try using the xml serialization instead of doing that. You have some resources here : https://stackoverflow.com/a/215659/5950070 – Cem.S Oct 01 '20 at 09:43

1 Answers1

2

The syntax { } for an empty object is valid in javascript, but not in C#.

For C# try one of the following:

dateRange.Item = new object(); // object without properties
// or
dateRange.Item = new { id = 1, text = "Hello" }; // object with 2 properties
// or
dateRange.Item = DateTime.Now; // a DateTime struct
// or
dateRange.Item = null; // *not* an object
Peter B
  • 22,460
  • 5
  • 32
  • 69