Saturday, June 30, 2007

Referencing WCF service from a Windows Application

I was playing with Windows Communication Foundation over the weekend and came over one very interesting peculiarity.

My WCF service uses Basic Http Binding, is hosted by IIS, and has the following method:

public List<string> GetCustomerList() {...}
Let's use a Windows Applications as a client (just note the fact that Form1 class was created by default). We create a reference to the service through a "Add service reference" wizard. Nothing fancy. The generated reference consists of .map XML and .cs proxy class - very similar to the Web Service reference.

Now the weird stuff - how, do you think, our method was mapped? Most likely your guess is wrong, - the return type is a BindingList type (never worked with that one):

System.ComponentModel.BindingList<string> GetCustomerList();
Huh? Let's remove this reference and add it again but prior to that get rid of all windows form classes in the application. Here is a newly generated mapping:
string[] ListProducts();
Tada! This is more anticipated result, as a generic list and array should be serialized exactly the same way.

I can't understand a possible logic behind that. Maybe it's just a bug but it is still not clear to me what a possible connection could be there. I am too lazy to try map a service with the different bindings but encourage anybody to try.


Anonymous said...

I have the same problem and tested your solulution (Adding the Servive Reference to an console application). After that I have copied the generated ".map" and ".vb" files to my windows application and everything works fine.
If I uses "Update Service Reference" in the windows application the problem din't occure again?!


Michael Goldobin said...

There is an unexpected behavior of a code generator - that's all. I didn't check your approach but it may as well work fine after you imported mapping and proxy files from the different application.

© 2008-2013 Michael Goldobin. All rights reserved