<?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>ChrisBellini.com &#187; Web Services</title>
	<atom:link href="http://www.chrisbellini.com/category/web-services/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisbellini.com</link>
	<description>test</description>
	<lastBuildDate>Mon, 21 Dec 2009 02:04:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>asp.net, you need to communicate more</title>
		<link>http://www.chrisbellini.com/2008/06/24/you-need-to-communicate-more/</link>
		<comments>http://www.chrisbellini.com/2008/06/24/you-need-to-communicate-more/#comments</comments>
		<pubDate>Tue, 24 Jun 2008 16:39:27 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASMX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.chrisbellini.com/?p=721</guid>
		<description><![CDATA[The topics I've been posting about lately have been somewhat varied; from Internet culture to hockey to politics to random thoughts.  Remember when I went on and on about programming?  Me too, so here goes.
This is for any ASP.NET coders out there Google-ing "There was an error processing the request".  I recently [...]]]></description>
			<content:encoded><![CDATA[<p>The topics I've been posting about lately have been somewhat varied; from Internet culture to hockey to politics to random thoughts.  Remember when I went on and on about programming?  Me too, so here goes.</p>
<p>This is for any <a href="http://msdn.microsoft.com/en-us/asp.net/" target="_blank">ASP.NET</a> coders out there Google-ing "There was an error processing the request".  I recently came across this issue, so I wanted to share what I've found to resolve it.  You've probably written an awesome web service with public methods that do awesome things and are so meticulously coded so as to adhere to all the hip programming concepts and best practices.  I'd bet that you're doing the right thing in your web service's public methods by capturing code that's prone to throwing exceptions like this:</p>
<pre class="c">&nbsp;
namespace FooService
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #66cc66;">&#91;</span>WebMethod<span style="color: #66cc66;">&#40;</span>EnableSession=<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    public <span style="color: #993333;">void</span> Foo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        try
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #808080; font-style: italic;">// Dangerous method alert</span>
            MyWildMethod<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
        catch <span style="color: #66cc66;">&#40;</span>Exception ex<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #808080; font-style: italic;">// Handle with grace.</span>
            CleanupWildMethod<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            throw new Exception<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Something happened - no worries.&quot;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>Perhaps you're calling this web service method via <a href="http://en.wikipedia.org/wiki/AJAX" target="_blank">AJAX</a> on your presentation layer pages and expecting this to come back in get_message():</p>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> UseMyWebService<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    FooService.<span style="color: #006600;">Foo</span><span style="color: #66cc66;">&#40;</span>SuccessCallback, ErrorCallback<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> ErrorCallback<span style="color: #66cc66;">&#40;</span>error<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Whoa: '</span> + error.<span style="color: #006600;">get_message</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>And it does in your development environment.  Then you deploy this to production and your lovely and friendly "Something happened...no worries" message turns into the user-unfriendly "There was an error processing the request" message.  What gives?</p>
<p>There's a good chance that you're using custom error pages in your project.  Your <em>Web.config</em> might have something like this in it:</p>
<pre>
&lt;customerrors mode="On"&gt;
      &lt;error statusCode="403" redirect="~/error.aspx?eid=403" /&gt;
      &lt;error statusCode="500" redirect="~/error.aspx?eid=500" /&gt;
      &lt;error statusCode="501" redirect="~/error.aspx?eid=501" /&gt;
      &lt;error statusCode="502" redirect="~/error.aspx?eid=502" /&gt;
&lt;/customerrors&gt;
</pre>
<p>If you do, you've successfully determined that users should see friendly error pages rather than cryptic ones that only programmers would understand.  Unfortunately, <a href="http://www.microsoft.com" target="_blank">Microsoft</a> hasn't figured this out yet and instead of allowing the user-friendly message in your exception to propagate back, they replace it with "There was an error processing the request".  There is a solution.  You could set the customErrors mode to "Off", but that would defeat the purpose.  Instead, ensure that your web service ASMX files are in a folder of their own.  Then, inside of that folder, create a basic <em>Web.config</em> that looks like this:</p>
<pre>
&lt; ?xml version="1.0"?&gt;

&lt;configuration&gt;
    &lt;appsettings /&gt;
    &lt;connectionstrings /&gt;
    &lt;system .web&gt;
      &lt;customerrors mode="Off" /&gt;
    &lt;/system&gt;
&lt;/configuration&gt;
</pre>
<p>That's all it takes to correct this oversight on Microsoft's part.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisbellini.com/2008/06/24/you-need-to-communicate-more/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
