Month: July 2008

Building and consuming anything but a trivial web service with Visual Studio can be quite an error prone task. The service itself is difficult to test outside of the web environment, the proxy class generated by Visual Studio will, most of the time, be in a conflicted state in your code repository as multiple developers add and change methods. It’s also quite cumbersome if you want to map those proxy classes back to your own classes. The list goes on and while Windows Communication Foundation does solve some of these issues I’d like to introduce you to the service infrastructure of Spring.Net which can help you to expose your services and is available on .net 2.0.

Let’s first look at the server side. Instead of decorating your service with webservice and webmethod attributes you can write a plain old c# object (poco) which can be tested like any other class and be hosted in multiple environments, exposing the service via remoting is just a configuration change. Nothing even prevents you from making a fat client, just keep the service itself behind an interface.

To make it available as a webservice you use the Webservice exporter which can be found in the Spring.Web assembly as illustrated below.

<objectid="ProductWebService"type="Spring.Web.Services.WebServiceExporter, Spring.Web"><propertyname="TargetName"value="ProductService"/><propertyname="Namespace"value="http://www.bennymichielsen.be/services"/><propertyname="Description"value="Defines operations upon products"/><propertyname="MemberAttributes"><dictionary><entrykey="RetrieveProducts"><objecttype="System.Web.Services.WebMethodAttribute, System.Web.Services"><propertyname="Description"value="Retrieves all products"/><propertyname="MessageName"value="RetrieveProducts"/></object></entry><entrykey="SearchProducts"><objecttype="System.Web.Services.WebMethodAttribute, System.Web.Services"><propertyname="Description"value="Searches for products which have a name like the one supplied."/><propertyname="MessageName"value="SearchProducts"/></object></entry></dictionary></property></object>

Using the Webservice exporter you can export any object in your configuration as a webservice, just point it to the appropriate object definition using the TargetName property. I’ve populated some more properties just to show how you can use this class. It is however necessary to have an interface(s) on your service, but since this is a best practice anyhow I don’t see this as a shortcoming.

On the client side a similar approach can be used to consume the webservice using the WebserviceProxy factory in the Spring.Services assembly. Using this class your code can depend upon the service interface instead of the proxy class itself. If you want to use the proxy class, this is still supported. In this case Spring will create a proxy which will implement the service interface and map to the Visual Studio proxy. Note that the original service does not have to implement this interface, the methods supplied in the interface are mapped using a kind of duck typing. This is very useful if you don’t control the service but are consuming it and don’t want to tightly couple your code.

If you do control both sides, it is much easier to let the proxy be generated at runtime.

This allows you to use the service interface, the concrete implementation is of no concern. What’s also very useful is that you can reuse all the classes which are already in the service contract assembly, thus preventing your solution from being polluted with any additional code.

After a little Cocoa break I’m back, while continuing through the book I seemed to have forgotten some stuff already, not good.

So, next up, Keyboard Events.

This chapter explains how the events are used for handling keystrokes as well as the first responder concept. The first responder being the active view element (button, text area,…) and there’s a whole mechanism working in the background when the first responder changes. Not a lot of ground breaking material here, probably the most important piece of code here is an example of how to code the fuzzy blue box around an active custom view.

Chapter 20, Drawing text with attributes.

Here we are taught how to show strings in various formats, not that interesting. One nice feature however is that all the drawing commands you write can be converted into PDF by the AppKit framework.

Chapter 21, Pasteboards and Nil-Targeted actions.

The clipboard in Windows, pasteboard in OS X. Different name, same concept, although I’ve never read about it in any .Net book I’ve seen but you know what it does :). What you need to remember from this chapter is that you can do a lazy paste. Meaning that you don’t have to put it in the clip errr pasteboard when the user presses the copy command. You can wait until he presses paste, very valuable if you’re working with large quantities of data.

Nil targeted actions are best explained with an example. You can set the selector (method signature for .net people) of a menu item to anything you want, say removeEmployee:, when the menu item’s target is nil and the menu item is invoked, it will traverse the responder tree until someone acts upon it.

Nothing fancy was covered in these past chapters, but you need to know about these things. I did spend quite some time on the applications, probably because there was a two week pause. For those interested I’ve attached all the source code.

Followed some links and found this podcast on deep fried bytes. It’s interesting to hear, although the title is a bit misleading. They talk about .net development 25% of the time using virualization tools like VM Ware, the rest of the podcast is filled with general switchers info and some recommended applications.

On the Spring forum someone asked if it was possible to add object definitions to the application context of classes which were beyond the searchable range of the application. I was a little bit sceptic at first but one debugging session later, I found out that it is possible to do this. Though I really don't support the whole idea of doing this.

When you are not using fully qualified assembly names in your definition Spring will look at the current loaded assemblies to resolve the type, so with this trick you can make it work. The topic can be found here and the source code can be found here, don't forget to change the path of the “ClassLibrary1” assembly to make it work.

At work the company firewall blocked the ports used by Adium to connect to the different IM services. One google later I was one happy user, information on where to find the screens to edit the preferences and which checkboxes to use can be found here.

So this was going a bit too easy. After installing a fresh copy of Windows XP, including SP2. I went to the update site which prompted me to install SP3, which I did. No problems so far, yet after the new service pack being deployed to the system windows update refused to install any further updates. It found, listed and downloaded them fine but every installation failed. Long story short, if you’re in this situation open up a command prompt. Click start, run, type in cmd and then click ok. In the command prompt type in regsvr32 %windir%system32wups2.dll and hit enter, this registers that dll. Go to the windows update site now, and you’ll have no problems.

At least three months have past since I had to rescue a PC in the family, a new record. One thing I keep forgetting is where, under Windows XP, Outlook Express stores its data. So I’m writing it down here for further reference.

Email messages can be found here: C:Documents and Settings(user name)Local SettingsApplication DataIdentities (under a sub folder there called Outlook Express). The files have a *.dbx extension.

The contact list can be found here: C:Documents and Settings(user name)Application DataMicrosoftAddress Book. The file has a *.wab extension, and it appears it’s prefixed with the user name.