Creating an Indigo client proxy that references the same service contract type as server does

So, you want to create an Indigo client proxy that references the same types as server does, IOW a client proxy that won't recreate ServiceContract (let’s say it is an interface IMyServContract). Before the actual process I'll shortly explain how you can actually automate the client proxy creation.

First you start by opening Windows SDK CMD Shell (it is handy since it has all paths to utilities set). Next you'll type something like:
svcutil /o:proxy.cs /config:app.config http://localhost/server/service.svc
svcutil is utility that generates both code and config file out from url for you. The problem with that syntax is that it will generate code for service contract, too (remember, we don’t want to regenerate the service contract since we are referencing it from both client and server) and even worse, the same service contract interface will have different signature. To help you out there is /r:assemblypath option to svcutil that tells it not to regenerate types found in that assembly. You’ll rewrite your command like this: svcutil /o:proxy.cs /config:app.config /r:myassembly.dll http://localhost/server/service.svc
and expect that it will act properly. Unfortunately this isn’t the case. There is a well known bug in svcutil that doesn’t generate proxy.cs anymore.

So, here is my quick and not exactly well tested solution.

  • Generate the proxy without /r option which will result in IMyServContract redeclaration.
  • Open the proxy.cs file and use Refactor/Rename on IMyServContract to change it to something else, let’s say IMyServContractProxy.
  • Then open generated config file and modify accordingly <client><endpoint contract> attribute to match renamed service contract.

And this is it. I tested on relatively simple sample and it worked. There is a drawback though – your proxy wont have original service contract implemented for the client by default (IOW it won’t implement IMyServContract). You can easily add implementation though as the code is already in place –

  • just add IMyServContract implementation declaration to *Proxy class (which now implements IMyServContractProxy because of renaming).

There you go with fully functional proxy that references the same service contract type as server does.

UPDATE: There is an infinitely easier way to achieve this (note that the solution above was really a quick and dirty solution). Clemens suggested that you don't need a proxy at all. Just create the channel and there you go - logical, since remoting works the same way. Currently I don't have time to test it though.

Swiss army knife kind of book about .net2 and C#2

The first thought that came to my mind when I got the book "Practical .Net2 and C#2: Harness the Platform, the Language, the Framework by Patrick Smacchia (MVP, author of NDepend)" was: "This one is huge". And it really is a huge book having nearly 900 pages. And this is both good and bad. The good side is that all of the pages are really useful and the bad one that it probably won't fit into your mailbox.

The book is divided into three parts:

  1. The .NET2 Platform
  2. C#2 Language
  3. The .NET2 Framework

The three parts cover what every C# developer should know (or any .NET developer if you neglect the second part and taking into consideration that the languge used is C#) before doing any coding. Especially the first part is of common interests to all .NET developers – it gives you the essential knowledge on how .NET works and what is going on behind the curtains. The second part deals with C# 2 language, and the third one describes the most common functionalities and uses of the framework.

It is not a book about boring syntax details. It is obvious that it was written by a programmer with the know-how and many years of experience – the word ‘practical’ in the title fits perfectly. I also liked the fact the Patrick mentions several (free) tools (i.e. Reflector) that are simply a must have.

I would say that this book is essential for beginners and a good read for skilled developers providing such a wide range of valuable information at hand in one place. Some chapters are really explained in details while others thoroughly cover the basics, leaving you with a good starting point.

All in all, I would say that this is a Swiss army knife kind of book and I warmly recommend it for anybody in .net (2) development.

Why is Introduce Local (Replace All) allowed in certain circumstances

Yesterday I had a repeat of my whole day presentation "What's new in Visual Studio 2005/.net 2" and the audience was great. Note: you can find the slides here. I was asked few questions which I promised to answer later because I didn't know them on the spot (yes, yes, I know). So, here is the first question answered:

Why is R! (both free refactor that comes with VB.NET and R! Pro) allowing Introduce Local (Replace All) operation on Double.Parse(TextBox1.Text) in the following situation:

After the Introduce Local (Replace All) operation we get this result, which is obviously faulty because the value should be different for d and c variables.

So, the question was whether this is a bug or by design (by design I mean: do this operation on your own risk)?
The answer is quite logical and simple: it is a bug and R! guys are woking on to fix it.

 

CodeSmith saves me time and money

An interesting feature of CodeSmith is that it tracks the number of lines generated for you. With this information and an fex approximations it calculates the hours and money saved (the money saved is wrongly calculated since it takes the amount of dollars and just changes the currency - obviously it doesn't work well for Slovene currency as 60SIT/hr is too low).

Mine did save me almost 30k hours and million 3/4 USD so far. Hey, I am a millionaire. Seriously, CodeSmith does an excellent work and I really don't see myself typing all those lines of code and looking at such data can give you a feeling of the work CodeSmith does.

Groove is groovy

I started using Groove and I have to admit that I like it. If you need to share you have to take a look at it - there is a 30 day trial version I think.
Briefly: Groove is modular - it has a concept of tools where each tool defines functionality such as discussions, file sharing, calendar, chat, etc. You wrap selected tools into a workspace which is shared across members. There is also security management which gives different permissions to each member. Groove allows you to share a file folder easily, too.

Certainly a product worth looking at.