<?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>Joel Hainley &#187; .NET</title>
	<atom:link href="http://www.joelhainley.com/index.php/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joelhainley.com</link>
	<description>my thoughts and adventures</description>
	<lastBuildDate>Mon, 19 Dec 2011 19:34:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ASP.NET AJAX AutoCompleteExtender not working</title>
		<link>http://www.joelhainley.com/index.php/2010/01/19/asp-net-ajax-autocompleteextender-not-working/</link>
		<comments>http://www.joelhainley.com/index.php/2010/01/19/asp-net-ajax-autocompleteextender-not-working/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 15:19:01 +0000</pubDate>
		<dc:creator>joelhainley</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET AJAX]]></category>
		<category><![CDATA[AutoCompleteExtender]]></category>

		<guid isPermaLink="false">http://www.joelhainley.com/?p=239</guid>
		<description><![CDATA[I was working on some new features for a client recently and they had a need for an AutoCompleteExtender on one of their forms. I hadn&#8217;t used the AutoCompleteExtender yet so I read through the documentation, coded up a webservice, and added  the appropriate items to the page and ran the app. When I tried [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on some new features for a client recently and they had a need for an AutoCompleteExtender on one of their forms. I hadn&#8217;t used the AutoCompleteExtender yet so I read through the documentation, coded up a webservice, and added  the appropriate items to the page and ran the app. When I tried typing into the TextBox that the AutoCompleteExtender was pointed at, nothing happened. In this posting I will detail the things that I looked at, and try to put together an accurate guide to making sure you&#8217;re AutoComplete works. I tried some of the &#8220;tips&#8221; that are out there after I had things working and they don&#8217;t help. So hopefully this will be a bit more definitive and useful than what I came across.</p>
<p>The first thing that I looked at was the method signature of the webservice. The <a href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete.aspx"title="Documentation"  onclick="javascript:pageTracker._trackPageview('/outbound/article/www.asp.net');">documentation</a> indicates that you need to use one of the following method signatures :</p>
<div class="codesnip-container" >public string[] GetCompletionList(string prefixText, int count) { &#8230; }</div>
<p>..OR..</p>
<div class="codesnip-container" >public string[] GetCompletionList(    string prefixText, int count, string contextKey) { &#8230; }</div>
<p>What the documentation doesn&#8217;t tell you is that the name/spelling/capitalization of the method signature must match EXACTLY. If you decide that you don&#8217;t like the camelcase on the prefixText and want to use prefixtext instead&#8230;.IT WON&#8217;T WORK. So make sure you have those signature matching correctly. I have seen some indications on the internet that you should use a static method such as :</p>
<div class="codesnip-container" >public static string[] GetCompletionList(string prefixText, int count) { &#8230; } // !!! DON&#8221;T DO THIS !!!</div>
<p>DON&#8217;T DO THIS. It doesn&#8217;t work. Only the exact methods defined in the documentation and shown above will work. </p>
<p>Back to my project, I get these methods defined properly, compile the project, go to my textbox start to type and still I get NOTHING. So I look over the documentation and see some information about the class/method attributes that must be added. The documentation shows the following :</p>
<div class="codesnip-container" >[System.Web.Services.WebMethod]<br />
[System.Web.Script.Services.ScriptMethod]<br />
public string[] GetCompletionList(<br />
    string prefixText, int count) { &#8230; }</div>
<p>What they don&#8217;t show in the documentation is that you need to also add the following to the class definition</p>
<div class="codesnip-container" >[System.Web.Script.Services.ScriptService]</div>
<p>So I make these changes and run the application again, and STILL it doesn&#8217;t work. I&#8217;m stumped. I put a break at the webservice method and run again and it&#8217;s not even hitting the webservice. After a little bit of digging I come across <a href="http://www.asp.net/AJAX/Documentation/Live/ConfiguringASPNETAJAX.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.asp.net');">Adding ASP.NET AJAX Configuration Elements to an Existing Web Site</a> and a lightbulb goes on. This project was not setup as an AJAX.NET site, in fact it predates ASP.NET AJAX by a couple of years. Sure enough as I start to dig through the documentation I notice mappings to handlers for the webservice calls. So I follow the changes specified and run the site and it worked!</p>
<p>It took me a while to get this figured out, and I suspect there might be a few others out there that might have some problems getting this working. Below is a complete class that you can use as a reference. I haven&#8217;t included any of the code defining the AutoCompleteExtender because the documentation seems sufficient and I didn&#8217;t have any problems. There is also a video on the ASP.NET AJAX site that walks you through configuring your first AutoCompleteExtender and does a good job, as long as your site is configured properly!</p>
<p>Good luck!</p>
<div class="codesnip-container" >using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Web;<br />
using System.Web.Services;<br />
using System.Web.Services.Protocols;<br />
using System.Web.Script.Services;<br />
using DALInterface;<br />
using CGWeb.framework;</p>
<p>namespace CGWeb.webservices {<br />
    /// <summary><br />
    /// Summary description for NewDXCompletion<br />
    /// </summary><br />
    /// </p>
<p>    [WebService(Namespace = "http://tempuri.org/")]<br />
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]<br />
    [ToolboxItem(false)]<br />
    [System.Web.Script.Services.ScriptService]<br />
    public class NewDXCompletion : System.Web.Services.WebService {</p>
<p>        [System.Web.Services.WebMethod]<br />
        [System.Web.Script.Services.ScriptMethod]<br />
        public string[] GetCompletionList(string prefixText, int count) { &#8230; }<br />
    }<br />
}</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.joelhainley.com/index.php/2010/01/19/asp-net-ajax-autocompleteextender-not-working/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>C# Partial Classes and NUnit</title>
		<link>http://www.joelhainley.com/index.php/2009/04/13/c-partial-classes-and-nunit/</link>
		<comments>http://www.joelhainley.com/index.php/2009/04/13/c-partial-classes-and-nunit/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 05:30:03 +0000</pubDate>
		<dc:creator>joelhainley</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[nunit]]></category>
		<category><![CDATA[partial classes]]></category>

		<guid isPermaLink="false">http://www.joelhainley.com/?p=136</guid>
		<description><![CDATA[Shad, a fellow developer and good friend, and I were hiking a great new loop I found in Mt. Diablo State Park the other day and after solving the rest of the world&#8217;s problems we eventually came around to talking about things that were driving us nuts in our current projects. We both had recently [...]]]></description>
			<content:encoded><![CDATA[<p>Shad, a fellow developer and good friend, and I were hiking a great new loop I found in Mt. Diablo State Park the other day and after solving the rest of the world&#8217;s problems we eventually came around to talking about things that were driving us nuts in our current projects. We both had recently found ourselves with code that was initially a quick and dirty library with a &#8220;Button 1&#8243; interface. ( You know the type, programmer&#8217;s make them. They have a single command button on them and you click them and then they do stuff..and never notify you when they are done, and don&#8217;t resize and a host of other things that a normal UI should have ). These &#8220;Button 1&#8243; quick and dirty apps have a nasty habit of turning themselves into indispensible tools for production/operations stuff.</p>
<p>The big problem we were both having was that while the apps were decent enough for their initial use we were being asked to extend them and both of us wanted to do some refactoring of the application before we released them into the wild. The best approach for this sort of thing is to develop unit tests so that, once refactored, we could be sure that we hadn&#8217;t broken anything important.</p>
<p>The biggest problem with dropping unit testing into an application after the fact is that sometimes you run into problems where you have to refactor just to get the unit tests access to all of the routines that you want to test. This isn&#8217;t an ideal situation, as you quickly end up wondering if you are breaking things just trying to get some unit tests built that are supposed to ensure you aren&#8217;t breaking anything. So you start wondering if instead of refactoring if you simply make functions that wrap your private functions and expose the behaviour might be the answer, pretty soon you have stuff everywhere and you wonder which is your testing code and which is your unit testing code to make all of this possible. Madness.</p>
<p>As we dropped off of the fire trail back into a heavily wooded area with a nice creek, it came up in conversation that perhaps partial classes were the way to go. If you haven&#8217;t used c# partial classes, you will. You can write class code in multiple files and yet at compile time it is assembled into a single logical unit. Several days later I had some free time and was able to verify that this would indeed work, I could drop all of my unit testing code into a single file that would provide all of the unit testing logic and wouldn&#8217;t muddy up the existing class. Furthermore, with a couple conditional complilation statements I could get rid of all of the unit testing code from the final release of the new library.</p>
<p>This is obviously not the approach you want to take if you can avoid it. It is arguable that you do not want your classes invaded in such a way for the purposes of unit testing. This is something you can work around if you use unit testing from the beginning, but what if you inherit a project and it doesn&#8217;t have any unit test capabilities built into it? What if the way that the classes are structured make unit testing pieces of the application difficult? Do you just plow forward and hope for the best? I hope not, and hopefully this stop gap measure to get unit tests built into the classes so that you can test existing functionality is the way to go. With these &#8220;nunit partials&#8221; in place you should be able to then start refactoring the rest of the application to be a little bit better structured for unit tests without having to risk dropping anything.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelhainley.com/index.php/2009/04/13/c-partial-classes-and-nunit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Example of Proxying Binary Data With ASP.NET</title>
		<link>http://www.joelhainley.com/index.php/2009/02/28/example-of-proxying-binary-responses-with-aspnet/</link>
		<comments>http://www.joelhainley.com/index.php/2009/02/28/example-of-proxying-binary-responses-with-aspnet/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 03:29:31 +0000</pubDate>
		<dc:creator>joelhainley</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[.NET C# Proxying Binary Responses]]></category>

		<guid isPermaLink="false">http://www.joelhainley.com/?p=129</guid>
		<description><![CDATA[Recently I was working on a project and needed to proxy a request to a website that was returning a binary file.  I ran into some problems with my first pass at a solution. I believe the problem was a consequence of proxying binary data without getting at the underlying streams. I&#8217;m not sure how [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was working on a project and needed to proxy a request to a website that was returning a binary file.  I ran into some problems with my first pass at a solution. I believe the problem was a consequence of proxying binary data without getting at the underlying streams. I&#8217;m not sure how often I&#8217;ll need to do this, but I thought it might be useful to post here for others to know about in case they ran into the same problem I did. So here&#8217;s the code that worked for me, hopefully it&#8217;ll work for you too.</p>
<hr/>
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(&#8221;http://to.some.binary.data&#8221;);<br />
req.Timeout = &#8220;blah&#8221;;<br />
req.Method = &#8220;GET&#8221;;</p>
<p>HttpWebResponse resp = (HttpWebResponse)req.GetResponse();<br />
Stream reader = resp.GetResponseStream();<br />
// you might want to set your responses content type here<br />
System.IO.Stream r = Response.OutputStream;</p>
<p>int Length = 256;<br />
Byte [] buffer = new Byte[Length];</p>
<p>int bytesRead = reader.Read(buffer, 0, Length);<br />
while(bytesRead &gt; 0){<br />
r.Write(buffer, 0, bytesRead);<br />
bytesRead = reader.Read(buffer, 0, Length);<br />
}</p>
<hr />
Hope that helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelhainley.com/index.php/2009/02/28/example-of-proxying-binary-responses-with-aspnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alternatives to Throwing Exceptions to Flex/Silverlight Clients From a .NET Web Service &#8211; part 2</title>
		<link>http://www.joelhainley.com/index.php/2009/02/07/alternatives-to-throwing-exceptions-to-flexsilverlight-clients-from-a-net-web-service-part-2/</link>
		<comments>http://www.joelhainley.com/index.php/2009/02/07/alternatives-to-throwing-exceptions-to-flexsilverlight-clients-from-a-net-web-service-part-2/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 00:10:00 +0000</pubDate>
		<dc:creator>joelhainley</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[.NET Webservices Exceptions Silverlight Flex]]></category>

		<guid isPermaLink="false">http://www.joelhainley.com/?p=125</guid>
		<description><![CDATA[In part 1 of this article I argued that exceptions sent &#8220;over the wire&#8221; to flex/silverlight clients from a webservice weren&#8217;t necessarily the right way to put things together. I argued that that exposing your clients to raw exceptions happening in your server was not elegant in the same way that throwing raw exceptions to [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.joelhainley.com/index.php/2009/01/22/throwing-exceptions-to-flexsilverlight-clients-from-a-net-web-service-part-1/"title="part 1"  >part 1</a> of this article I argued that exceptions sent &#8220;over the wire&#8221; to flex/silverlight clients from a webservice weren&#8217;t necessarily the right way to put things together. I argued that that exposing your clients to raw exceptions happening in your server was not elegant in the same way that throwing raw exceptions to a user in a windows desktop app was not elegant. In talking about the last article with some people I realized that I needed to make a point. There are times when an exception is appropriate, and I&#8217;m not advocating avoiding exceptions altogether. My point was that I felt people were relying on exceptions too heavily when a more appropriate method might be possible.</p>
<p>Let&#8217;s take a look at input validation to see what we mean about relying too heavily on exceptions. Validation is a bear, you want to try and have your validation rules in one spot only. This way you can avoid the chore of duplicating validation logic on the client and the server. This seems to be one of the main reasons people are looking at bubbling exceptions over the wire because if they can simply put the validation logic in the server side, then they can throw an exception back to the client and deal with it there. It solves the the problem of duplication of validation logic and allows developers to deal with validation errors in the same way that they do within desktop application environments.</p>
<p>The question now becomes can we avoid exceptions and still provide for a rich validation environment? I believe that we can and I&#8217;m going to spend the rest of this article describing an approach. It may not be the best approach, it may not be the only approach, but it was worked well for me on the last few projects and enough people I&#8217;ve talked to about the approach seem to feel that it&#8217;s powerful enough to consider for their future efforts along these lines.</p>
<p>In order to provide a framework upon which to hang our theory let&#8217;s consider a simplified method of a web service named &#8220;CreateAccount&#8221; that takes as it&#8217;s only parameter an Account object.</p>
<p style="text-align: center;"><a href="http://www.joelhainley.com/wp-content/uploads/2009/02/20090207-account.png" ><img class="alignnone size-medium wp-image-126 aligncenter" title="20090207-account" src="http://www.joelhainley.com/wp-content/uploads/2009/02/20090207-account.png" alt="Account UML" width="176" height="201" /></a></p>
<p style="text-align: left;">When we want to create a new account we will fill out the information about the account as described and then pass it to the CreateAccount method of the webservice. However, instead of just having a void for the return value and throw exceptions if there are errors you simply use a response object such that the method signature would look something like the following :</p>
<blockquote>
<p style="text-align: left;">CreateAccountResponse  CreateAccount( Account acct)</p>
</blockquote>
<p style="text-align: left;">This is certainly not a new concept. Response objects litter many namespaces, but in this particular situation they allow us to avoid having a lot of exceptions flying out of our webservice and doing all sorts of ridiculous plumbing hacks to get it all to operate nicely.  Now let&#8217;s take a quick look at the CreateAccountResponse class and see what it looks like, then we can talk about how a response object allows us to avoid duplicate validation and exceptions. Below is the UML for the CreateAcountResponse object</p>
<p style="text-align: center;"><a href="http://www.joelhainley.com/wp-content/uploads/2009/02/20090207-createaccountresult.png" ><img class="alignnone size-medium wp-image-127" title="20090207-createaccountresult" src="http://www.joelhainley.com/wp-content/uploads/2009/02/20090207-createaccountresult.png" alt="" width="174" height="234" /></a></p>
<p style="text-align: left;">We see that this class mmics the Account class pretty closely with the addition of a couple of routines that would be needed to actually communicate results. The Success flag would indicate whether the account creation was successful and the error message would only be filled out if there was a particular error that you wanted to communicate to the user such as &#8220;You do not have the rights to create accounts&#8221; or something along those lines. The other fields would be filled out if there were problems with the validation of the individual fields of the account object. This would allow us to have all of the validation/error messages specified on the server side in a single location and still be able to get the information out to your users. Such that if you require the state field to be only 2 characters long and someone puts in 4 you could set the success flag to false and then add error text to the State field of the response object that could then be displayed to the end user.</p>
<p style="text-align: left;">WIth this approach if there was an exception generated in the webservice, we could trap it server side and provide the appropriate message to the CreateAccountResponse object and not have to require the client to exception handling just to know what is happening.</p>
<p style="text-align: left;">Now one of the complaints  that I have heard about this approach is &#8220;but now you have to create all of these response objects&#8221;. Well yeah, but one way or another you&#8217;re going to have to write some code to deal with errors and wouldn&#8217;t it be nice if you could deal with the errors and the error messages in a single place? Also you could simply create a generic results object that would suffice for most of the calls that you want to make. Then again consider that in some of the more mature environments such as .NET WebServices  you can easily create webservices that provide this sort of functionality and the WSDL&#8217;s and whatnot are all created for you.So it&#8217;s not nearly as much work to do this as it could be.</p>
<p style="text-align: left;"><em><strong>What about the overhead of all of these custom classes? </strong></em>Is it really any more overhead than the throwing of exceptions? Exception throwing, and handling are expensive operations. I find it a little be cleaner to my thinking because now you have a clear and concise definition of what you need to program against when you are dealing with your WebService&#8217;s API.</p>
<p style="text-align: left;">I&#8217;m not saying this is necessarily the best approach for all occassions, and I&#8217;m not really down on exceptions in general, or even for web services. However I think that there are many times when the extra effort you have to go through just to get robust exception handling done will lead you into a lot of needless efforts. Especially if you are just trying to provide validation/failure information back to the client applications.Keep in mind that what I&#8217;ve presented here isn&#8217;t a blueprint, it&#8217;s more like a pattern of how you might consider structuring your webservices in certain situations.</p>
<p style="text-align: left;">Your mileage may vary.</p>
<p style="text-align: left;">
]]></content:encoded>
			<wfw:commentRss>http://www.joelhainley.com/index.php/2009/02/07/alternatives-to-throwing-exceptions-to-flexsilverlight-clients-from-a-net-web-service-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight : Communication Exception was unhandled by user code</title>
		<link>http://www.joelhainley.com/index.php/2009/02/04/silverlight-communication-exception-was-unhandled-by-user-code/</link>
		<comments>http://www.joelhainley.com/index.php/2009/02/04/silverlight-communication-exception-was-unhandled-by-user-code/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 18:13:20 +0000</pubDate>
		<dc:creator>joelhainley</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[clientaccesspolicy.xml]]></category>

		<guid isPermaLink="false">http://www.joelhainley.com/?p=124</guid>
		<description><![CDATA[Ran into the following error the other day :
An error occurred while trying to make a request to URI &#8216;http://localhost/T2WS/AdminServices.asmx&#8217;. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact [...]]]></description>
			<content:encoded><![CDATA[<p>Ran into the following error the other day :</p>
<blockquote><p>An error occurred while trying to make a request to URI &#8216;http://localhost/T2WS/AdminServices.asmx&#8217;. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. Please see the inner exception for more details.</p></blockquote>
<p>The error message was self-explanatory but it didnt&#8217; solve the problem. I had my cross domain file setup appropriately and yet I was still receiving the error. As seen below the stack trace didn&#8217;t offer much help either:</p>
<blockquote><p>System.ServiceModel.CommunicationException was unhandled by user code<br />
Message=&#8221;An error occurred while trying to make a request to URI &#8216;http://localhost/T2WS/AdminServices.asmx&#8217;. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. Please see the inner exception for more details.&#8221;<br />
StackTrace:<br />
at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)<br />
at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)<br />
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)<br />
at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)<br />
at T2SL.T2AdminService.AdminServicesSoapClient.AdminServicesSoapClientChannel.EndgetAccountList(IAsyncResult result)<br />
at T2SL.T2AdminService.AdminServicesSoapClient.T2SL.T2AdminService.AdminServicesSoap.EndgetAccountList(IAsyncResult result)<br />
at T2SL.T2AdminService.AdminServicesSoapClient.EndgetAccountList(IAsyncResult result)<br />
at T2SL.T2AdminService.AdminServicesSoapClient.OnEndgetAccountList(IAsyncResult result)<br />
at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)<br />
InnerException: System.Security.SecurityException<br />
Message=&#8221;"<br />
StackTrace:<br />
at System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)<br />
at System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)<br />
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)<br />
InnerException: System.Security.SecurityException<br />
Message=&#8221;Security error.&#8221;<br />
StackTrace:<br />
at System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)<br />
at System.Net.BrowserHttpWebRequest.&lt;&gt;c__DisplayClass5.&lt;EndGetResponse&gt;b__4(Object sendState)<br />
at System.Net.AsyncHelper.&lt;&gt;c__DisplayClass2.&lt;BeginOnUI&gt;b__0(Object sendState)<br />
InnerException:</p></blockquote>
<p>Still no luck, i spent some time fiddling with the clientaccesspolicy.xml file but it didn&#8217;t seem to be the problem. After a bit of digging and avoiding the obvious, it finally hit me right between the eyes. I had setup the Silverlight project to be the startup and it was running the file locally, instead of running it through the web project I had setup to wrap Silverlight with.</p>
<p>Once I changed the startup project to the Web project and the file to the Silverlight testpage everything worked just fine and dandy except that the Silverlight project wasn&#8217;t updating. Looking through the Silverlight project properties I was able to point the build for the Silverlight &#8220;executable&#8221; to the Web project&#8217;s ClientBin directory and everything fell into place.</p>
<p>I just mention this hear because I&#8217;m sure I&#8217;ll forget how I solved this problem the next time I run into it. <img src='http://www.joelhainley.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelhainley.com/index.php/2009/02/04/silverlight-communication-exception-was-unhandled-by-user-code/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Alternatives to Throwing Exceptions to Flex/Silverlight Clients From a .NET Web Service &#8211; part 1</title>
		<link>http://www.joelhainley.com/index.php/2009/01/22/throwing-exceptions-to-flexsilverlight-clients-from-a-net-web-service-part-1/</link>
		<comments>http://www.joelhainley.com/index.php/2009/01/22/throwing-exceptions-to-flexsilverlight-clients-from-a-net-web-service-part-1/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 17:57:45 +0000</pubDate>
		<dc:creator>joelhainley</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[C# .NET services FLEX Silverlight]]></category>

		<guid isPermaLink="false">http://www.joelhainley.com/?p=123</guid>
		<description><![CDATA[I&#8217;ve been doing a lot of work with webservices talking to Flex clients recently. When I first started doing this work I spent some time trying to figure out how to get exceptions thrown to be picked up by the client and dealt with there. I read through the literature on doing such things, and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing a lot of work with webservices talking to Flex clients recently. When I first started doing this work I spent some time trying to figure out how to get exceptions thrown to be picked up by the client and dealt with there. I read through the literature on doing such things, and even spent some time evaluating some third party libraries for making all of this happen.</p>
<p>Recently I was at a .NET users group meeting and heard some people talking about throwing exceptions to Silverlight clients in much the same way that I had been looking at doing for my Flex clients. The problems that they encountered and the solutions that they came up with were essentially the same. &#8220;IIS does dumb stuff with the response codes when there&#8217;s an exception in a webservice&#8221;. (There&#8217;s a pretty simple work around for this one ) &#8220;You can trap the exception and then make the exception object a property of the service response object&#8221;, &#8220;There&#8217;s a third party product X, that wil&#8230;blah blah blah&#8221;. It was nice to see that noone had come up with an elegant solution to this &#8220;problem&#8221; of throwing exceptions over the wire.</p>
<p>I started to wonder if it really was a &#8220;problem&#8221;. I took a step back and did some critical thinking about such an approach. I had a lot of questions about what I, and the rest of the people out there are trying to accomplish by throwing exceptions &#8220;over the wire&#8221;.</p>
<ul>
<li>What benefits do you get from handling server exceptions in the UI?</li>
<li>Is it really correct to handle exceptions in the UI for problems that occurred in the web service?</li>
<li>What are the valid uses for exceptions?</li>
<li>What is the definition of an exception?</li>
<li>What are people trying to do with these exceptions?/ What problems are they trying to solve by the use of exceptions?</li>
</ul>
<p>In an effort to clear up my thinking on such things I&#8217;m going to go through some of the above questions below.</p>
<p><em>What is the definition of an exception?</em></p>
<p>The tongue in cheek response to this question is &#8220;it&#8217;s when something exceptional happens&#8221;. The longer explanation is that when your code encounters something that that is outside the scope of what it was intended to handle. I think there&#8217;s a clue in there that addresses the problem I&#8217;m trying to deal with, but we&#8217;ll have to get back to it after we talk about a few more of the questions.</p>
<p><em>What are the valid uses for exceptions?</em></p>
<p>Answering this question is difficult without having a problem domain to work with. The answer can vary depending upon the environment that your code is expected to run in, how reliable various parts of the environment are, how critical certain operations within your application are, etc..etc.. What I would like to say about this is that like we said above your exceptions should handle exceptional situations.</p>
<p>I also think that there is often too little thought put into the implementation of exceptions within an application. There&#8217;s a pretty good argument floating around that your exception model should be diagrammed and managed in the same way that your business objects are. I might talk about this at a later date, but for now give it some thought.</p>
<p>Is it really correct to handle exceptions in the UI for problems that occurred in the web service?</p>
<p>In a windows application that is self contained, handling exceptions in the form code  seems to be something that a lot of people are comfortable with (  judging by the codebases I&#8217;ve had to maintain ). In fact most books that I run across that show beginning development have the exception handling directly in the form itself. This is arguably correct, if not desirable, for quick and dirty applications, because you&#8217;re really just trying to get something done. Besides you don&#8217;t want to throw the actual exception out to the user to look at so you catch the exception and give the user a nice &#8220;Something really bad happened, try again&#8221; message and exit the application.</p>
<p>Now in a situation where you have a client application talking to a server application. You have a different scenario. The server is providing services to the client, if something bad happens in the server it should handle the problem in some way, (i.e. capturing the exception ) and then notify the client that there has been an error.</p>
<p>In the same way that you would never want to throw raw exceptions from your self contained application out to your users. You really don&#8217;t want to throw raw exceptions to the clients that use your server API. If there was a problem with your server code handle it gracefully in your server code and provide your clients with a decent error message.</p>
<p>There should be a separation between your server code and your client code, when you start to throw exceptions from your server out to your clients  you begin to tie them together in ways that are not extensible. Consider if you start using a new library in your server code that throws a different type of exception that you felt should be bubbled out to your client. This means that all of your clients will need to be updated to handle the new exception instead of handling a &#8220;call failed&#8221; response sort of message. Encapsulation is a metaphor for good design at all magnification levels of developement not just at the object/class level.</p>
<p>There is more I could say here but I&#8217;m going to move on for now. I might come back and talk some more about this in another posting.</p>
<p><em>What are people trying to do with these exceptions?/ What problems are they trying to solve by the use of exceptions?</em></p>
<p>From what I&#8217;ve observed most people are trying to ease their burden on the server side by throwing exceptions out to the clients when there are problems. The most common example of this is input validation, or even a little deeper would be business object validation (i.e. Does this user have the right to add another user to this account ) Call me crazy but I don&#8217;t see how you can call a user entering incorrect values to be an exceptional situation. At least with my users it never is. If there is a wrong value that can be typed, they are going to type it. I don&#8217;t start throwing exceptions and stepping out of the program flow to deal with these errors because they are not exceptional circumstances.  I have a really hard time believing that validation of input is a good place to start throwing exceptions. Yes, the system should reject bad input, or illegal operations but do you really need to start throwing exceptions over the wire to deal with this? Is it necessary to tightly couple your UI code base to your server codebase just to get the proejct done and avoid duplication of validation efforts?</p>
<p>I really don&#8217;t think so.</p>
<p>In the next part of this article I am going to provide some diagrams, patterns and maybe even a little sample code to show how you might avoid &#8220;exceptions over the wire&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelhainley.com/index.php/2009/01/22/throwing-exceptions-to-flexsilverlight-clients-from-a-net-web-service-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adventures in ORM on .NET 3.5</title>
		<link>http://www.joelhainley.com/index.php/2008/12/26/adventures-in-orm-on-net-35/</link>
		<comments>http://www.joelhainley.com/index.php/2008/12/26/adventures-in-orm-on-net-35/#comments</comments>
		<pubDate>Fri, 26 Dec 2008 17:27:00 +0000</pubDate>
		<dc:creator>joelhainley</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ATG]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Repository]]></category>

		<guid isPermaLink="false">http://www.joelhainley.com/?p=117</guid>
		<description><![CDATA[I&#8217;ve been working on a project in .NET 3.5  and  Adobe Flex 3 and have been having a good time getting the base architecture in place. I&#8217;ve spent the last couple of weeks looking at two ORM technologies available in .NET. NHibernate and LINQ for Entities. 
I started started out working with NHibernate because I was [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a project in .NET 3.5  and  Adobe Flex 3 and have been having a good time getting the base architecture in place. I&#8217;ve spent the last couple of weeks looking at two ORM technologies available in .NET. NHibernate and LINQ for Entities. </p>
<p>I started started out working with NHibernate because I was familiar with Hibernate in the java world. Well actually, I was familiar with the Repository from ATG which is pretty similar to Hibernate. (My general impression is that ATG&#8217;s Repository is a bit more polished than Hibernate) NHibernate worked out great and very quickly I was able to get the database access up and running and had a working prototype. Once this was done, I did some more digging to see what other ORM implementations were available for .NET.  There are quite a few projects out there but I came across LINQ, and specifically LINQ for Entities.</p>
<p>LINQ could probably best be described as a generalized approach at data access from various datasources that is intended to replace all of the customized query languages/approaches ( SQL, XPath, iteration through various collection classes, etc ) with a single language. Ostensibly this will reduce the amount of stuff a developer needs to know to be effective. According to the available documentation LINQ for Entities is the most customizable implementation of ORM functionality available in LINQ. There are some other ways to do similar things with a little less control using LINQ to SQL but I decided to just dig deep as the sort of control I was used to with Hibernate was most similar to LINQ for Entities.</p>
<p>I had to upgrade Visual Studio 2008 to sp1 to use LINQ for Entities, but this was trivial and I soon had things up and running. In short order I had everything working with LINQ and the application was moving forward again. At this point I&#8217;m mostly impressed with LINQ and I think I&#8217;ll end up using it for this project. There are a bunch of tools available in the IDE to support the mapping operations, and it will autogenerate initial classes by simply pointing the IDE at the database you are using.</p>
<p>I&#8217;m not sure if LINQ is the be all end all that microsoft is hoping it will be. I&#8217;m not convinced that a generalized query language is needed. It has been said, by several philosophers and more than a couple of programmers, that the language that you have available to express yourself has an impact on your thinking. In this case specialized languages such as XPath and SQL give your mind a set number of ways to express yourself that are consistent with the underlying implementation. Yet a generalized approach abstracts that away and removes you another step farther away from the realities of the toolset you are using. Is this a good thing? Time will tell and at the very least it will be interesting to see how far people can take this approach to querying various datasets. </p>
<p>The thing I am convinced about is that ORM technology is making it much easier on developers to quickly and easily get database code up and running. The increases in productivity are real. It is nice to interact with the data as objects instead of as sql queries, stored procedures, etc. Somehow I suspect that the Smalltalk crowd is sitting in the wings chuckling at all of the other technology platforms touting their ORM solutions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelhainley.com/index.php/2008/12/26/adventures-in-orm-on-net-35/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A quick note about .NET Web Services, Adobe Flex and Namespaces</title>
		<link>http://www.joelhainley.com/index.php/2008/11/01/a-quick-note-about-net-web-services-adobe-flex-and-namespaces/</link>
		<comments>http://www.joelhainley.com/index.php/2008/11/01/a-quick-note-about-net-web-services-adobe-flex-and-namespaces/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 18:52:31 +0000</pubDate>
		<dc:creator>joelhainley</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[.NET c# webservices web services flex]]></category>

		<guid isPermaLink="false">http://www.joelhainley.com/?p=95</guid>
		<description><![CDATA[I was building out some .NET based web services for a Flex project I&#8217;ve been working on and bumped up against something that gave me a bit of trouble. When you create a .NET Web Service there is a namespace attribute associated with the service. Here&#8217;s an example (in c#) :
namespace HelloWebService
{
[WebService(Namespace = "http://www.examplenamespace.com/")]
[WebServiceBinding(ConformsTo = [...]]]></description>
			<content:encoded><![CDATA[<p>I was building out some .NET based web services for a Flex project I&#8217;ve been working on and bumped up against something that gave me a bit of trouble. When you create a .NET Web Service there is a namespace attribute associated with the service. Here&#8217;s an example (in c#) :</p>
<blockquote><p>namespace HelloWebService<br />
{<br />
[WebService(Namespace = "http://www.examplenamespace.com/")]<br />
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]<br />
[ToolboxItem(false)]</p>
<p>public class Service1 : System.Web.Services.WebService<br />
{</p>
<p>// implementation &#8230;</p>
<p>}</p></blockquote>
<p>This value is required by .NET for a web service, or at the very least .NET gets VERY upset if this value is not set.</p>
<p>You will then need to let Flex know about this namespace in order to access the results. To do this you simply add the following lines to Flex:</p>
<blockquote><p>private namespace lh = &#8220;http://www.examplenamespace.com/&#8221;;<br />
use namespace lh;</p></blockquote>
<p>Not much to it, but it can be a bit of a pain when you&#8217;re not aware of this. Flex doesn&#8217;t complain, it just gives you empty values when you try to access the values.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelhainley.com/index.php/2008/11/01/a-quick-note-about-net-web-services-adobe-flex-and-namespaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

