473,414 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Validating XML Document using XSD in WCF Service

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.

Expand|Select|Wrap|Line Numbers
  1.   public string CheckXMLData(XmlDocument xmlDoc)
  2.         {
  3.             TheXsd = "Customer.xsd";
  4.  
  5.             //load schema 
  6.             XmlSchemaCollection xsc = new XmlSchemaCollection();
  7.             xsc.Add("Customer", TheXsd);
  8.             Validate(xmlDoc, xsc);
  9.             return " Validation Result";
  10.         }
  11.  
  12.         public string Validate(XmlDocument xmlDoc, XmlSchemaCollection xsc)
  13.         {
  14.             XmlTextReader reader = null;
  15.             XmlValidatingReader vreader = null;
  16.  
  17.             //reader = new XmlTextReader(xmlDoc);
  18.             reader = new XmlTextReader(xmlDoc.ToString());
  19.             vreader = new XmlValidatingReader(reader);
  20.             vreader.Schemas.Add(xsc);
  21.             vreader.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
  22.             try
  23.             {
  24.                 while (vreader.Read()) { }
  25.             }
  26.             catch
  27.             {
  28.                 return Output = "XML Document is not well-formed.";
  29.             }
  30.             vreader.Close();
  31.             return Output;
  32.         }
  33.  
  34.         public void ValidationCallBack(object sender, ValidationEventArgs args)
  35.         {
  36.             Outcome = "<font color=\"red\">Failed:</font>";
  37.             Output += "Validation error: <font color=\"red\">" + args.Message + "</font><br>";
  38.         }
  39.  
Apr 21 '10 #1
3 8149
Monomachus
127 Expert 100+
@Arulmanoj
To create a WCF take a look at this.Creating, Configuring and Consuming a WCF service in IIS 7 In mean time please explain what exactly is going wrong? What do you really need?
Apr 21 '10 #2
Hi Monomachus,

I want to validate a xml file and against a xml schema using a WCF service in C#. I will be sending the XML file as a XML document to the WCF service. The service will validate the XML file against the predefined scheme file in the service. Here I am not able to write a method to get XML file as input from the client who is consuming the service. I am using XmlTextReader and XmlValidatingReader to read and validate the XML file.

Thanks
Manoj
Apr 22 '10 #3
@Monomachus
Hi Monomachus,

I want to validate a xml file and against a xml schema using a WCF service in C#. I will be sending the XML file as a XML document to the WCF service. The service will validate the XML file against the predefined scheme file in the service. Here I am not able to write a method to get XML file as input from the client who is consuming the service. I am using XmlTextReader and XmlValidatingReader to read and validate the XML file.

Thanks
Manoj
Apr 27 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jari Kujansuu | last post by:
I can successfully parse XML document using SAX or DOM and I can also validate XML document against schema. Problem is that my program should deal with user-defined schemas which means that when...
1
by: Andy | last post by:
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. ...
1
by: neoret | last post by:
Hi there. I need to perform an upload of a document using HTTP post. This has to be done from my windows form using C#. My challenge is: 1: To send - the word document 2: To attach several...
1
by: JSL | last post by:
How to insert images into a Microsoft Word document using VB.NET?? my code: Public Function PictureReport() (it doesn't work!!!) On Error Resume Next Dim oDoc As Word.Document Dim range As...
3
by: Lord0 | last post by:
I *think* I need to be able to validate subsets of an XML document using different schema. The functionality I'm trying to implement is this. a) External suppliers produce an XML document...
3
by: SMH | last post by:
Normally an SVG document is loaded/parsed/interpreted inside an HTML document using an 'object' (or 'embed') element, although there are supposedly other ways too. The problem is, the SVG document...
0
by: menelty | last post by:
Hi, I have been trying to create a word document using vb.net. I have several fields I wish to populate so I am using a MS Access back end to spit out the requested data for these fields as the...
1
by: vin4tony | last post by:
Anyone plz help to open a word document using asp.net.I used a code ..but it shown access denied...Can anyone help me.. my error is Access is denied. Description: An unhandled exception occurred...
0
by: shivapadma | last post by:
i want to know how multiple tables are added to the MS word document using vb.net i wrote following code to insert one table in MS word document using vb.net 1.opened MS word document 2.inserted...
6
by: Sajeena | last post by:
<?php // starting word $text = "My Text"; //Start MS Word $Word = new COM("word.application") or die("Failure: Word did not start"); echo("WORD has started."); //Formating the Font...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.