<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Rant: Don't return XML in string variables!</title><link>http://blogs.msdn.com/b/mpowell/archive/2004/05/12/130637.aspx</link><description>I have probably seen a half a dozen article submissions to MSDN in the last year with authors who do the following: 
 
 
 // Bad Bad Bad [WebMethod] public string MyLameWebMethod() { XmlDocument dom = new XmlDocument(); // load some XML ... return</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>High-Performance Web Services: Avoid XmlNode, Use IXmlSerializable</title><link>http://blogs.msdn.com/b/mpowell/archive/2004/05/12/130637.aspx#570224</link><pubDate>Thu, 06 Apr 2006 22:45:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:570224</guid><dc:creator>Kirk Allen Evans' Blog</dc:creator><description>Avoid returning XmlNode from a web service method at all costs. &amp;nbsp;In this post, I show why you should avoid returning XmlNode in web services, and demonstrate how to use the IXmlSerializable interface in .NET 2.0 web services for high performance XML serialization&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=570224" width="1" height="1"&gt;</description></item><item><title>National Weather (Web) Service</title><link>http://blogs.msdn.com/b/mpowell/archive/2004/05/12/130637.aspx#276010</link><pubDate>Tue, 07 Dec 2004 02:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:276010</guid><dc:creator>Matt Powell</dc:creator><description>&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=276010" width="1" height="1"&gt;</description></item><item><title>re: Rant: Don't return XML in string variables!</title><link>http://blogs.msdn.com/b/mpowell/archive/2004/05/12/130637.aspx#180091</link><pubDate>Sun, 11 Jul 2004 17:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:180091</guid><dc:creator>yn</dc:creator><description>Why go through the trouble of instantiating an XmlDocument, XmlReader or even an XPathNavigator if you already have the XML as a string to begin with and have no interest in interacting with it in that context?&lt;br&gt;&lt;br&gt;Let's take Oracle's (9i+) xmltype for example. It holds and returns XML as CLOB, which you normally cast to string. Assuming I simply want to forward this record from Oracle to my client, without interacting with it at all, why waste time and space over deserialization?&lt;br&gt;&lt;br&gt;In the client I can simply (assuming client is the browser in this sample and 'result' is callService's callback argument):&lt;br&gt;&lt;br&gt;var xmlDoc=document.createElement(&amp;quot;xml&amp;quot;);&lt;br&gt;xmlDoc.loadXML(result.value);&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=180091" width="1" height="1"&gt;</description></item><item><title>How to return well-formed XML from WebServices without the DOM: from XmlReader and XPathNavigator</title><link>http://blogs.msdn.com/b/mpowell/archive/2004/05/12/130637.aspx#144949</link><pubDate>Mon, 31 May 2004 19:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:144949</guid><dc:creator>TrackBack</dc:creator><description>&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=144949" width="1" height="1"&gt;</description></item><item><title>re: Rant: Don't return XML in string variables!</title><link>http://blogs.msdn.com/b/mpowell/archive/2004/05/12/130637.aspx#144952</link><pubDate>Mon, 31 May 2004 16:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:144952</guid><dc:creator>Daniel Cazzulino</dc:creator><description>It's not necessary at all to load a DOM to return well-formed XML from a webservice. And as the DOM will be the &amp;quot;legacy-deprecated-dying&amp;quot; API in .NET, it only makes sense to move to XmlReader and XPathNavigator-based processing.&lt;br&gt;Here's how you can return well-formed XML without wasting server resources in loading DOMs you don't need: &lt;a target="_new" href="http://weblogs.asp.net/cazzu/archive/2004/05/31/144922.aspx"&gt;http://weblogs.asp.net/cazzu/archive/2004/05/31/144922.aspx&lt;/a&gt; (How to return well-formed XML from WebServices without the DOM: from XmlReader and XPathNavigator)&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=144952" width="1" height="1"&gt;</description></item><item><title>re: Rant: Don't return XML in string variables!</title><link>http://blogs.msdn.com/b/mpowell/archive/2004/05/12/130637.aspx#142602</link><pubDate>Wed, 26 May 2004 21:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:142602</guid><dc:creator>Tim Huffam</dc:creator><description>What about loose coupling?  &lt;br&gt;&lt;br&gt;Bundling various parameters into an primitive type like a string (like the MSCRM APIs do)provides a simple way to acheive loose coupling does it not?&lt;br&gt;&lt;br&gt;Tim&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=142602" width="1" height="1"&gt;</description></item><item><title>Rant continued again: Don't put XML in Strings</title><link>http://blogs.msdn.com/b/mpowell/archive/2004/05/12/130637.aspx#132222</link><pubDate>Fri, 14 May 2004 23:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:132222</guid><dc:creator>Matt Powell</dc:creator><description>&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=132222" width="1" height="1"&gt;</description></item><item><title>re: Rant: Don't return XML in string variables!</title><link>http://blogs.msdn.com/b/mpowell/archive/2004/05/12/130637.aspx#132107</link><pubDate>Fri, 14 May 2004 18:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:132107</guid><dc:creator>Shaun McDonnell</dc:creator><description>What about Classic ASP object incompatability?&lt;br&gt;&lt;br&gt;For example, if I have an &amp;quot;Account&amp;quot; object on my .NET side of things and decide make that object a return value in my .NET Web Service, will ASP know how to handle the object?  I don't think so.&lt;br&gt;&lt;br&gt;In order to keep my .NET apps object-oriented, we just serialize our objects into Xml like this:&lt;br&gt;&lt;br&gt;&amp;lt;I&amp;gt;&lt;br&gt;Account asq = new Account()&lt;br&gt;StringWriter swQuery = new StringWriter();&lt;br&gt;			XmlSerializer xsQuery = new XmlSerializer(typeof(Account));&lt;br&gt;			xsQuery.Serialize(swQuery, asq);&lt;br&gt;return swQuery.ToString();&lt;br&gt;&amp;lt;/I&amp;gt;&lt;br&gt;&lt;br&gt;Is there a better way to do this in order to avoid returning a string of Xml?  I know the overhead is enormous and would love to know the answer.  Thanks!&lt;br&gt;&lt;br&gt;Shaun McDonnell&lt;br&gt;Citigroup&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=132107" width="1" height="1"&gt;</description></item><item><title>Rant Continued: Avoiding the DOM?</title><link>http://blogs.msdn.com/b/mpowell/archive/2004/05/12/130637.aspx#131379</link><pubDate>Thu, 13 May 2004 22:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:131379</guid><dc:creator>Matt Powell</dc:creator><description>&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=131379" width="1" height="1"&gt;</description></item><item><title>re: Rant: Don't return XML in string variables!</title><link>http://blogs.msdn.com/b/mpowell/archive/2004/05/12/130637.aspx#131309</link><pubDate>Thu, 13 May 2004 17:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:131309</guid><dc:creator>Michaeljon Miller</dc:creator><description>Yup, agreed about the MS-CRM interfaces. There's a lot of history around why they're shaped the way they are, but that doesn't really matter any more. We (that is, the MS-CRM team) are looking at a bunch of approaches to make this all better in upcoming releases and I'll try to post some information as I can.&lt;br&gt;&lt;br&gt;The problem was really one of timing and a requirement to handle type extensibility in the field. The timing problem is simple - the only tool available when we started MS-CRM was ATL server (and only in beta). Sure, we ended up slipping way past the VS.Net release date, but that's a different story. The type extensibility problem is that customers want to and need to change the shape of their entities on the fly. There were no types available for ATL server that we could leverage that could automatically extend (struct would never work, it's hard-coded in the type system), so we ended up choosing strings.&lt;br&gt;&lt;br&gt;XML strings as parameters suck. They suck at the programming model level for both the client and the service. Building XML strings is error prone to say the least. But they also suck for type safety reasons on the wire. Trust me, I've stared at enough netmon traces of our stuff to get dizzy - it would be tremendously better if we had objects.&lt;br&gt;&lt;br&gt;We're getting there. Slowly, but we're getting there. All I can recommend right now, and it's a short term hack, is to look at Dan Roger's &amp;lt;a href=&amp;quot;&lt;a target="_new" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=de0cc46b-4dea-4786-9eb0-8733e41bf5a8&amp;amp;DisplayLang=en&amp;quot;&amp;gt;XSDObjectGen&amp;lt;/a&amp;gt;"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyID=de0cc46b-4dea-4786-9eb0-8733e41bf5a8&amp;amp;DisplayLang=en&amp;quot;&amp;gt;XSDObjectGen&amp;lt;/a&amp;gt;&lt;/a&gt; tool and build classes from the XSD (it's what I do when I'm programming against the CRM SOAP interfaces). Although, on that topic, the V1.0 XSD were buggy out of the box. I think v1.2 fixed it and if not I might be persuaded to hand out the right fix.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=131309" width="1" height="1"&gt;</description></item></channel></rss>