Skip to main content

Posts

Showing posts from June, 2010

XQuery - Projecting Attributes With a Where Clause a Query

Had to write an xquery yesterday to extract some attribute values from an xml column, so I thought of posting it here for future reference. This the structure of my XML data stored in the column xmlColumn This is the records that I have in my table What I need is to select the Id column from a normal table column and then the "value" attributes from the xml coulumn whose "SiteText" is equal to 1 This is the query written in 2 different ways select id, xmlColumn. query('data(AuditRecord/Records/Record[@SiteText=1]/@value)') from temp select id, xmlColumn. value('data(AuditRecord/Records/Record[@SiteText=1]/@value)[1]', 'varchar(50)') from temp and this is the result set I get

Validating XML with an XSD using LINQ

So how do you validate an XML document that you get with a particular XSD?. One way you can do is with LINQ to XML with these steps. 1) Create a XmlSchemaSet 2) Add the schemas that your document needs to confirm to 3) Call the validate method of the XDocument So here is the example code. //Load an xml document XDocument doc = XDocument.Load(@"C:\test.xml"); //Define the schema set XmlSchemaSet set = new XmlSchemaSet(); //Add the schema to the set set.Add(string.Empty, @"C:\test.xsd"); //A variable to test whether our document is valid bool isValid = true; //Cal the validate method //Note that I am using a lambda function , alternativley you can use //pass in a delegate method as in the traditional method :) doc.Validate(set, (o, e) => { isValid = false; }); //Print out the result Console

Exposing Enum Types From WCF

There are many cases where you would want to expose enum types from a WCF service, so how do you do this? Simply create a data contract and mark the values with the EnumMember attribute and thats it [DataContract] public enum MyEnumName { [EnumMember] CSV, [EnumMember] XML = 2 }

The maximum nametable character count quota (16384) has been exceeded

Some of our services were growing and the other day it hit the quote, I could not update the service references, nor was I able to run the WCFTest client. An error is diplayed saying " The maximum nametable character count quota (16384) has been exceeded " The problem was with the mex endpoint, where the XML that was sent was too much for the client to handle, this can be fixed by do the following. Just paste the lines below within the configuration section of the devenve.exe.config and the svcutil.exe.config files found at the locations C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE , C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin Restart IIS and you are done. The detailed error that you get is the following : Error: Cannot obtain Metadata from net.tcp://localhost:8731/ Services/SecurityManager/mex If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. F