Is XSD data validation reliable in .Net 4.0? - vb.net

I have written a client to a public SOAP web service, using a WSDL and several XSD files supplied by the service provider. I wanted to find an easy way to validate user data against the XSD files, so I used the standard example from MSDN, using an XmlSchemaSet for the XSD files, an XmlReader and a validation routine to catch the error messages. (The code is available at http://msdn.microsoft.com/en-us/library/as3tta56.aspx) It works for some data elements, but others do not throw an error when they are invalid. If I include "ValidationFlags = ValidationFlags Or XmlSchemaValidationFlags.ReportValidationWarnings", I then get a lot of warnings, e.g. "Could not find schema information for the element 'MyRequest'", "Could not find schema information for the attribute 'TheDate'", etc. But I can open the XSD files in the VS2010 IDE, and its XML Schema Explorer shows these elements and attributes.
So my main question to anyone who is familiar with validating XML data in VS2010 in this way is, are there limits to the complexity of the XSD files that the XmlReader validation can handle? Could the prefixes for the Target Namespaces confuse the XmlReader? There are thousands of complex types defined in the schema, spread across 7 XSD files, which is why I wanted this to be handled automatically, rather than me writing a validation routine for each user input field.
Thanks in advance.

The .NET validation may not be perfect, yet it's among the best in the industry. One issue they have for sure is with the schema loader (we use our own), which sometimes gets fooled too easily (I would say). Beside the above, I am not aware of any other limitations, along the lines you described. We routinely use .NET XmlSchemaSet to load and validate XSDs spread across hundreds of files, in all sort of namespace combinations, and with thousands of elements, types, etc.

Related

Accessing a single RavenDB from different applications

I have a web project that stores objects in raven db. For simplicity the classes live in the web project.
I now have a batch job that is a separate application that will need to query the same database and extract information from it.
Is there a way I can tell raven to map the documents to the classes in the batch job project that have the same properties as those in the web project.
I could create a shared dll with just these classes in if that's needed. seems unnecessary hassle though
As long as the structure of the classes you are deserializing into partially matches the structure of the data, it shouldn't make a difference.
The RavenDB server doesn't care at all what classes you use in the client. You certainly could share a dll, or even share a portable dll if you are targeting a different platform. But you are correct that it is not necessary.
However, you should be aware of the Raven-Clr-Type metadata value. The RavenDB client sets this when storing the original document. It is consumed back by the client to assist with deserialization, but it is not fully enforced. The logic basically is this:
is there ClrType metadata?
if yes, do we have that type loaded in the current app domain?
if yes, then deserialize into that type
if none of the above, then deserialize dynamically and cast into the type
requested (basically, duck-typing)
You can review this bit of the internals in the source code on github here.

Need suggestions on which option will be efficient to store data on iPad

This is my first time that I am working on a big project for a client. So I was not sure how to solve this problem. However I have come up with two different ideas but I need professionals opinion about which one is better :)
Situation :
There is an application which runs on different client's iPad. Application data is stored by using giant XML file. This XML file is shared among all client by a server. So a server has a centralised copy and each client has their own copy. Once client made changes to their XML copy they updates server copy in and other client updates their copy by updated server copy.
Now only one client can make changes at one time, To fix this I have logic by which before client starts editing XML they need to get ownership from server and server will only allow one client to edit at one time.
Visual Representation :
Now on client side I have to think of a logic by which I will update my client copy and upload it to server. There are two options,
Option 1 :
In option 1, I can directly manipulate XML file by using GDataXML parser and upload that copy to server. For persistence I can save client copy on my iPad in document directory.
Option 2 :
In option 2, I can read XML file create a CoreData representation for local storage. When ever I update data inside core data it will I will change XML file too and than upload that file on server. Double work but I guess better persistence.
Now which one more robust and advisable? Personally I was planning to do option 2 because it seems more robust as I am persisting application data in core data. But option 1 seems more easy work but I don't know how good persistency will remain.
Sorry for lengthy question,
Thanks for any input given.
There are a number of factors which would influence selecting the second option over the first.
How big is the XML file? If you need to work with very large documents, you may need to incrementally parse the XML (SAX) into core data. This will allow you to access the document's contents without loading it all into memory at once.
Do you need to run complex queries in the data? If so, you may be better off using core data fetch predicates, rather than xpath or XSL.
Are you already using core data? Depending on how the XML data is structured, it might be simpler overall to import the data into your existing persistent store.
Otherwise, you can probably make due with parsing the entire document and either traversing the resulting tree or querying with xpath.
If you need to create an object graph based on what you get from server and show it to user (which you most probably need to do), you should stick up to second option, since it allows easy and robust data persistence.
If you do not need to present user with any data from the XML file you can, of course, store it in the Documents directory.
So, if this is a client application and it has at least some visual representation of the data from an XML file you should use CoreData.
If you want a regular update of data , then use CoreData

How to avoid name-clashes in xsds between BizTalk messages and WCF service datacontracts

Consider the following: I have BizTalk project and inside it I have placed xsd schemas for messages.
Those schemas are in namespace "A". I have another web service, it uses datacontract with namespaces "A" too.
So when I add a service reference to the first project which is Biztalk, VS generates schemas for datacontracts that are in the second project.
Thus I have 2 schemas with the same namespace and root element.
OK I think I can see your problem now. My question would then be why do you have the name-clash in the first place? If the generated schemas are generated from a running instance of your service then you do not need to code your own schemas, you can just use the generated ones.
Or, I can understand this a different way: the schemas you have developed are for a different purpose, but they just happen to share the same root node name and namespace as the generated schemas. In this case you should refactor your non-generated schemas by either changing the target namespace and/or the root node name.
It is best practise never to re-use target namespaces across messages in BizTalk server. Infact when you build your solution the compiler issues a warning when you do this.
Is this possible for you to do this?

How to handle multiple data sources in one WCF Domain Service?

I'm working on creating a WCF Domain Service which at the moment provides access to a database. I created the Entity Model, added the DomainService (LinqToEntitiesDomainService) and everything works so far.
But there are cases when my data doesn't come from the DB but somewhere else (for instance an uploaded file). Are there any best practices out there how to handle this different data sources properly without resorting to writing two completely different data providers? It would be great to access both types with one interface. Is there already something I can use?
I'm fairly new to this so any advice apart from that is highly appreciated.
How many cases where the data comes from a file? How many files? How will you know if a file is there? Are you going to poll the directory? what format are the files? (XML support is possible)
Microsoft's documentation suggests that you can create a custom host endpoint, but I don't know what limitations there are.

Make application 'single file' and get rid of XML config file

I have this pretty simple application, it uses a webService to transfer data to my servers DataBase. Now it is very important for me to keep this application as one single file, and not having some XML files needed for it to work, but this is the case. I think the XML file holds the information to this webService, so without it the application crashes. Is there a way to get the application to work without this XML file, or a way to put the XML inside the exe archive?
Any way to accomplish this is much appreciated.
It sounds like what you want to do is invoke a web service programmatically (without a Visual-Studio-added web reference). Another potentially useful link here.
I imagine all of the configuration settings that exist in an app.config file can be hard-coded in one way or another, the various config sections will just require varying degrees of ingenuity to make it happen.