I use C#, .NET 4.5, Console application. I added WSDL file in service reference. Inside WSDL are validation rules like:
<xs:complexType name="xRequest">
<xs:sequence>
<xs:element name="SenderDateTime" type="ip:grDateTime"/>
<xs:element name="SenderId" type="ip:grIdentifier"/>
</xs:sequence>
</xs:complexType>
There is XSD file too, with details of validation rules like:
<xs:simpleType name="grDateTime">
<xs:restriction base="xs:dateTime">
<xs:pattern value="[0-9]{4,4}\-[0-9]{2,2}\-[0-9]{2,2}[T][0-9]{2,2}:[0-9]{2,2}:[0-9]{2,2}(\.[0-9]{1,6}){0,1}"/>
</xs:restriction>
</xs:simpleType>
And I have automatically generated properties from WSDL in Reference.cs like:
public partial class xRequest
{
private string senderIdField;
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public string SenderId {
get {
return this.senderIdField;
}
set {
this.senderIdField = value;
this.RaisePropertyChanged("SenderId");
}
}
}
I serialize xRequest object into XML and I want to validate it. How can I validate XML with XSD, when part of validation rules are in WSDL?
It's not as straight forward as it should be... Look at this article (Step 4, 5 and 11), I think it is essentially what you want to do (client side) but it also shows how to do the validation server side.
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