<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Software Warlock &#187; xml</title>
	<atom:link href="http://softwareblog.morlok.net/category/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://softwareblog.morlok.net</link>
	<description></description>
	<lastBuildDate>Sat, 24 Dec 2011 16:06:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Naming collision in ASMX web service</title>
		<link>http://softwareblog.morlok.net/2010/07/02/naming-collision-in-asmx-web-service/</link>
		<comments>http://softwareblog.morlok.net/2010/07/02/naming-collision-in-asmx-web-service/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 20:32:55 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=392</guid>
		<description><![CDATA[I ran into an interesting problem today while working on an ASMX web service. Everything compiled fine, but when I went to view the ASXM in the browser to manually invoke the methods to test it, the normal automatically generated &#8230;<p class="read-more"><a href="http://softwareblog.morlok.net/2010/07/02/naming-collision-in-asmx-web-service/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>I ran into an interesting problem today while working on an ASMX web service.</p>
<p>Everything compiled fine, but when I went to view the ASXM in the browser to manually invoke the methods to test it, the normal automatically generated info page didn&#8217;t come up.  Trying to grab the WSDL also gave me a blank page.</p>
<p>I then attached the debugger to IIS to observe what was happening when I tried to view the ASMX info page.  By breaking on exceptions, I was able to uncover the following error:</p>
<p><em>The XML element &#8216;XXX&#8217; from namespace &#8216;http://tempuri.org/&#8217; references a method and a type. Change the method&#8217;s message name using WebMethodAttribute or change the type&#8217;s root element using the XmlRootAttribute.</em></p>
<p>With a little more thinking, I was able uncover what I believe was going on.</p>
<p>I had defined a complex type to return as a response:</p>
<pre name="code" class="c#">
public class FooResponse {...}

[WebMethod]
public FooResponse Foo() {...}
</pre>
<p>Note that here the exact name pairing of Foo/Foo+Response is important. When I changed the method name as follows, the problem went away:</p>
<pre name="code" class="C#">
public class FooResponse {...}

[WebMethod]
public FooResponse Fooxxx() {...}
</pre>
<p>What I believe is happening is .NET is attempting to automatically wrap the response coming from the Foo method with an element named FooResponse. The use of that same name as the object you want to return creates ambiguity. By changing the name of my response object, or the name of my method I was able to avoid this collision.</p>
<p>I have also posted this information in response to a <a href="http://stackoverflow.com/questions/580042/c-web-service-client-multiple-web-service-methods-with-same-complex-return-ty/">question</a> on StackOverflow.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2010/07/02/naming-collision-in-asmx-web-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XSLT with Optional Extension Object</title>
		<link>http://softwareblog.morlok.net/2009/12/08/xslt-with-optional-extension-object/</link>
		<comments>http://softwareblog.morlok.net/2009/12/08/xslt-with-optional-extension-object/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 02:41:13 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=315</guid>
		<description><![CDATA[Extension objects provide a convenient way to allow an XSL transform to interact with the outside world. They can also be used to offload computations that are difficult to express in XSL. Recently, I ran into a scenario where I &#8230;<p class="read-more"><a href="http://softwareblog.morlok.net/2009/12/08/xslt-with-optional-extension-object/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Extension objects provide a convenient way to allow an XSL transform to interact with the outside world.  They can also be used to offload computations that are difficult to express in XSL.</p>
<p>
Recently, I ran into a scenario where I wanted to write an XSLT that would use an extension object to record some additional information about intermediate steps of the transform.  The extension object was not required, however, and I wanted to leave it up to the user of the XSLT as to if they wanted to use the extension object.
</p>
<p>
The question then became how to conditionally execute calls to the extension object.  Suppose you have the following extension object defined in C#:
</p>
<pre name="code" class="C#">
public class FooExtensionObject
{
  private List&lt;string> recordedValues = new List&lt;string>();

  public void RecordValue(string val)
  {
    recordedValues.Add(val);
  }
}
</pre>
<p>Now suppose this extension object is used in the following XSLT:</p>
<pre name="code" class="xml">
&lt;xsl:transform
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:foo="urn:FooExObj">
  &lt;template match="/">
    ...
    &lt;xsl:value-of select="foo:RecordValue(@bar)"/>
    ...
  &lt;/template>
&lt;/transform>
</pre>
<p>The extension object is supplied to the XSLT through the arguments:</p>
<pre name="code" class="C#">
XslTransform transform = new XslTransform();
transform.Load("SomeFile.xsl");

XsltArgumentList args = new XsltArgumentList();
FooExtensionObject aFoo = new FooExtensionObject();
args.AddExtensionObject("urn:FooExObj", aFoo);

XmlTextWriter myWriter = new XmlTextWriter("output.xml", null);

transform.Transform(xpathDoc, args, myWriter);
</pre>
<p>
In the case where the extension object is not supplied, however, this XSLT will cause an error.  To correct this issue, you can use the <tt>function-available</tt> function.  Change the transform as follows:
</p>
<pre name="code" class="xml">
...
&lt;xsl:if test="function-available('foo:RecordValue')">
  &lt;xsl:value-of select="foo:RecordValue(@bar)"/>
&lt;/xsl:if>
...
</pre>
<p>
The conditional statement blocks out the use of the extension object when it does not exist.  Unfortunately, you must do this where ever you wish to use the extension object.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2009/12/08/xslt-with-optional-extension-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

