I writing a WCF service to get a xml file as input and validate it against a schema. I have done the validation part. But I don't know how to write method in WCF service to get xml file as input.
Below i have given code i have written in WCF service.
Below i have given code i have written in WCF service.
Code:
public string CheckXMLData(XmlDocument xmlDoc)
{
TheXsd = "Customer.xsd";
//load schema
XmlSchemaCollection xsc = new XmlSchemaCollection();
xsc.Add("Customer", TheXsd);
Validate(xmlDoc, xsc);
return " Validation Result";
}
public string Validate(XmlDocument xmlDoc, XmlSchemaCollection xsc)
{
XmlTextReader reader = null;
XmlValidatingReader vreader = null;
//reader = new XmlTextReader(xmlDoc);
reader = new XmlTextReader(xmlDoc.ToString());
vreader = new XmlValidatingReader(reader);
vreader.Schemas.Add(xsc);
vreader.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
try
{
while (vreader.Read()) { }
}
catch
{
return Output = "XML Document is not well-formed.";
}
vreader.Close();
return Output;
}
public void ValidationCallBack(object sender, ValidationEventArgs args)
{
Outcome = "<font color=\"red\">Failed:</font>";
Output += "Validation error: <font color=\"red\">" + args.Message + "</font><br>";
}
Comment