I'm implementing a C# web service that is supposed to accept a custom message including unbounded number of elements.
Originally, the object is defined in a XSD file like below:
<xsd:element name="LogMessage">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="1" name="avantlog" type="tns:LogEventType">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="LogEventType">
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="1" name="context" type="tns:ContextType">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ContextType">
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="unbounded" name="severity" type="xsd:string">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
And, in a CS file implementing the web service, I prepared a struct for this:
public struct logevent
{
public ContextType context;
public struct ContextType
{
public string[] severity;
}
}
However, when I tried to access an element of the 'serverity' using a line,
String temp = logevent.context.severity.GetValue(0).ToString()
, the program throws a following error:
"Index was outside the bounds of the array."
When I changed the element from 'unbounded' to '1' in the XSD file and also modified 'public string[] severity;' to 'public string severity;', it works.
Can anyone help me to make the web service to accept a message including unbounded numbers of elements?
While 87 percent of U.S. households use some type of air conditioning, central AC systems are the most sought-after for both convenience and accessibility. If flipping a switch for whole-house cooling is what you're after, you may wonder whether it's possible to install your own. And the answer is, you definitely can.
The code that corresponds to specified XSD (if serialized using XmlSerializer) is the following:
[XmlRoot("LogMessage"]
public class LogMessage
{
[XmlElement("avantlog")]
public LogEventType AvantLog {get; set;}
}
public class LogEventType
{
[XmlArray("context")]
[XmlArrayItem("severity")]
public string[] Severity {get; set;}
}
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