In the first part of this article I showed how I’ve been testing code using MEF and a generic base class that is in charge of wiring up the dependencies.
In this part I will focus on how I got WCF to wire up my web service using MEF in what I think is quite an elegant way.
My first requirement was to be able to write a web service that will use dependencies (imports) but that wouldn’t require me to write the composition code in the service class itself. Most of the examples I saw online didn’t provide me with a good way to do that unfortunately.
Until I came across this excellent post by Tim Roberts which shows how to tap into the WCF pipe-line and have your services composed automatically instead of having to do it per service or including wire-up code in your classes.
While the code Tim provided was a great start I thought it wasn’t just right for me. Specifically it was the fact that it required custom code in the Global.asax file which for me was not as elegant as it should be.
So I’ve done a bit more digging into the WCF pipe-line and discovered that I could achieve an elegant, completely configuration-based solution by implementing my own endpoint behavior.
In the end I needed to only create 3 classes to achieve this: EndpointComposedElement, ComposedEndpointBehavior and ComposedInstanceProvider.
Continue reading “Unit Testing, WCF and MEF – Part 2”
This article will focus on how I’ve adopted unit testing in .NET using MEF and how to also apply this to WCF web services.
I haven’t been dedicated to unit testing for a long time but once I started I couldn’t stop. There are many great benefits to doing unit tests, I wont list them here but a good article to read is at: Agitar.com
What made me build something on my own? I wanted something light that I could also integrate into existing code without making too many changes. So I focused on a couple of things: Testing and Dependency Injection. I wanted an elegant solution that didn’t rely on external libraries or that will require a steep learning-curve.
In this article I will focus on these topics and how I solved it for myself. I’m not going to dive into other topics such as The SOLID principals, TDD, Dependency Injection, Mocking, etc. If these terms are not familiar to you, I suggest you read up on them first.
I’m actually going to divide this article into two parts, to keep them shorter and to the point:
Continue reading “Unit Testing, WCF and MEF”
A couple of weeks ago I announced the release of the first .NET implementation of the Gravatar API.
Gravatar.NET is available for download on Codeplex.
What I’d like to show in this article is how to make use of the library using jQuery and WCF to create your own Gravatar client (Ponderi.com style).
This article will demonstrate how to show a user their Gravatar account images, allow the user to activate a different image or delete it.
I will build upon many of the concepts I described in an earlier article I wrote called: “Creating a Webservice Proxy with jQuery”. So if you like, check it out first as I won’t go into the basics in this article.
Continue reading “Creating a Gravatar client with jQuery and WCF”
For a while now I’ve been working on an implementation of the Gravatar public API.
Unfortunately it took longer than I had intended, what with those pesky work commitments and personal life issues…
I’m glad to tell you that Gravatar.NET is now available for download on Codeplex.
If you don’t know what Gravatar is, it’s: “A Globally Recognized Avatar”, allowing you to store a personal image (or images) and reuse it across different websites that support the use of it (example: WordPress.com).
If you’re building a website that includes storing user account information, and let’s face it, what website doesn’t do that these days, then typically one of the things your users expect is to be able to associate a photo to recognize their account on the site. Instead of having to store and manage these photos on your server (sometimes with a bandwidth/storage limit), Gravatar can do it for you.
Continue reading “Announcing Gravatar.NET”
Updated (25/06/2010): Fixed typos in code example
Updated (16/11/2012): Fixed missing comma.
I have been working on a website recently and one of the pages on the site has a main functionality of showing dynamic results returned from a AJAX
call to a WCF service.
As I was developing and continuously testing with Firefox I was happy to see that my code was working well; based on the URL the results on the page will differ as expected.
However, When it came to test the page with Internet Explorer the results were dramatically different… No matter what the URL was the same content from my initial request kept appearing on the screen! Quickly enough I realized that it wasn’t something wrong with my code but with IE, after all in Firefox and Chrome it was working just fine.
So naturally, I googled for a solution and found this StackOverflow thread that confirmed to me that this was indeed an issue with IE. Unfortunately, the good answers there were only helpful to those who use jQuery to initiate the AJAX requests but I was using the proxy generated automatically by ASP.NET, so I had to find my own solution as I was unable to find anything useful online.
Below are ways you can use to fix the problem. First, I’ll show how to fix it when using the MS Service Proxy and then how to fix it when using jQuery.
Continue reading “IE Caching Ajax Results – How to fix”
In this post id like to show a useful way of combining a few technologies (WCF, jQuery, MS AJAX Library and jTemplates) together in a way that might not be readily apparent to everyone. Continue reading Tying in WCF, JSON and jTemplates