473,320 Members | 1,862 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,320 software developers and data experts.

XML Validation Test

I have a DataContract from a WCF service that exists in a proxy assembly.

I want to create a test client for calling this service, so I thought I
would create an instance of the contract through Reflection, serialize to an
XmlDocument and then walk through the Xml creating textboxes and labels as I
go.

Problem is I also want to make sure I use the right controls, so things like
using a Calendar control for dates, checkbox for boolean.

I figured I could use the DataContractSerializer and XsdDataContractExporter
for create the Xml, get the XSD from the class and assign the resulting
XmlSchemaSet to the XmlDocument.Schemas collection. This works, but I still
cannot get to the XmlNode.SchemaInfo.SchemaType.BaseSchemaType property of a
node within the XmlDocument.

Any ideas?

Thx,

CD
May 30 '07 #1
4 4019
Competitive Dad wrote:
I figured I could use the DataContractSerializer and XsdDataContractExporter
for create the Xml, get the XSD from the class and assign the resulting
XmlSchemaSet to the XmlDocument.Schemas collection. This works, but I still
cannot get to the XmlNode.SchemaInfo.SchemaType.BaseSchemaType property of a
node within the XmlDocument.
Can you show us the relevant code, in particular the order in which you
set the Schemas property and call the Load method?
It might help to call the Validate method to ensure the nodes have type
annotations.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 30 '07 #2
Martin,

I sure can. This is what I have:

Type contract = ProxyAssembly.GetType(contractName);
MethodInfo method = contract.GetMethod(operationName);
ParameterInfo[] parameters = method.GetParameters();
List<XmlDocumentxmlDocs = new List<XmlDocument>();
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);
DataContractSerializer dcs;
XmlDocument doc;
XsdDataContractExporter dce;
foreach (ParameterInfo parameter in parameters)
{
object inst =
ProxyAssembly.CreateInstance(parameter.ParameterTy pe.FullName);
dce = new XsdDataContractExporter();
dce.Options = eo;
dce.Export(parameter.ParameterType);
dcs = new DataContractSerializer(parameter.ParameterType);
dcs.WriteObject(xtw, inst);
doc = new XmlDocument();
doc.LoadXml(sw.ToString());
doc.Schemas = dce.Schemas;
xmlDocs.Add(doc);
}

Without going in to too many specifics, I'm generating a dynamic proxy on a
WCF service using some code I found, and then using the assembly created to
get the methods on the contract and the parameters of those methods.

I then want create an instance of the class, serialize it, use the
XsdDataContractExporter to get the XSD definitions for the class and then
assign them to the XmlDocument schemas collection. If I then take a look at
any node within my XmlDocument to get back the SchemaInfo, it is null.

This is driving me mad, I think I'm probably missing something really
simple. I think I may need to validate first but using an XmlSchemaValidator
seems onerous at best.

I need to the types because I then want to generate and ASP.NET form with
appropriate controls (checkbox for boolean, etc.) to allow testing the client.

I originally wanted to use InfoPath, but it doesn't work with WSHttpBinding,
and nor do any of the other tools out there!!

Thx,

CD

"Martin Honnen" wrote:
Competitive Dad wrote:
I figured I could use the DataContractSerializer and XsdDataContractExporter
for create the Xml, get the XSD from the class and assign the resulting
XmlSchemaSet to the XmlDocument.Schemas collection. This works, but I still
cannot get to the XmlNode.SchemaInfo.SchemaType.BaseSchemaType property of a
node within the XmlDocument.

Can you show us the relevant code, in particular the order in which you
set the Schemas property and call the Load method?
It might help to call the Validate method to ensure the nodes have type
annotations.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 30 '07 #3
Competitive Dad wrote:
Type contract = ProxyAssembly.GetType(contractName);
MethodInfo method = contract.GetMethod(operationName);
ParameterInfo[] parameters = method.GetParameters();
List<XmlDocumentxmlDocs = new List<XmlDocument>();
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);
DataContractSerializer dcs;
XmlDocument doc;
XsdDataContractExporter dce;
foreach (ParameterInfo parameter in parameters)
{
object inst =
ProxyAssembly.CreateInstance(parameter.ParameterTy pe.FullName);
dce = new XsdDataContractExporter();
dce.Options = eo;
dce.Export(parameter.ParameterType);
dcs = new DataContractSerializer(parameter.ParameterType);
dcs.WriteObject(xtw, inst);
doc = new XmlDocument();
doc.LoadXml(sw.ToString());
doc.Schemas = dce.Schemas;
xmlDocs.Add(doc);
Consider a different approach, if you want type annotations on the
XmlNodes then don't use the LoadXml method, instead use e.g.
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ValdiationType = ValdiationType.Schema;
readerSettings.Schemas = dce.Schemas;
using (XmlReader xmlReader = XmlReader.Create(new
StringReader(sw.ToString()), readerSettings))
{
doc.Load(xmlReader);
}
xmlDocs.Add(doc);

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 30 '07 #4
Martin,

Fantastic, that works a treat. Many thanks for your help, that is now firmly
in my memory for next time!!

Cheers,

CD

"Martin Honnen" wrote:
Competitive Dad wrote:
Type contract = ProxyAssembly.GetType(contractName);
MethodInfo method = contract.GetMethod(operationName);
ParameterInfo[] parameters = method.GetParameters();
List<XmlDocumentxmlDocs = new List<XmlDocument>();
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);
DataContractSerializer dcs;
XmlDocument doc;
XsdDataContractExporter dce;
foreach (ParameterInfo parameter in parameters)
{
object inst =
ProxyAssembly.CreateInstance(parameter.ParameterTy pe.FullName);
dce = new XsdDataContractExporter();
dce.Options = eo;
dce.Export(parameter.ParameterType);
dcs = new DataContractSerializer(parameter.ParameterType);
dcs.WriteObject(xtw, inst);
doc = new XmlDocument();
doc.LoadXml(sw.ToString());
doc.Schemas = dce.Schemas;
xmlDocs.Add(doc);

Consider a different approach, if you want type annotations on the
XmlNodes then don't use the LoadXml method, instead use e.g.
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ValdiationType = ValdiationType.Schema;
readerSettings.Schemas = dce.Schemas;
using (XmlReader xmlReader = XmlReader.Create(new
StringReader(sw.ToString()), readerSettings))
{
doc.Load(xmlReader);
}
xmlDocs.Add(doc);

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 31 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
6
by: MickG | last post by:
Hi, I am trying to validate these values, this seems to work fine for the phone number and name but I am trying to get the program to fail to submit and set the focus on the date when 2006 is...
16
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate...
7
by: Ryan Ternier | last post by:
We're running a site that has required field validation on the login page. It works fine on our development / test machines. However, when I upload this site to our live server i get this error. ...
2
by: Humberto Alvarez | last post by:
Hi All I'm using asp requiredfieldvalidator and regularexpressionvalidator to validate a text field and a file input field respectively. The validation messages (the text property of the...
6
by: tshad | last post by:
I have been having some issues trying to get validation to work. On most of my pages, I have no problem. But I have a page that has 4 validation objects and none are displaying an error...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
0
by: Lucky Star | last post by:
Hello All, We have the following requirement. Please send matching profiles along with the rate Expectations, Availability and Contact Details for the same. Position: Lead Validation...
4
by: Chris | last post by:
Hi, i want to validate a textbox like this: <asp:TextBox ID="vrg" runat="server" Width="495px" TextMode=MultiLine/> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.