Archive

Archive for January, 2009

Best of WCF, January 25, 2009

January 25th, 2009

Two way client server network communication

A question on StackOverflow about 2 way WCF communication.  The answers provide some excellent links to resources concerning WCF duplex messaging.  Chapter 5 of Juval Lowy’s excellent Programming WCF Services has a lengthy discussion on Duplex messenges including Server/Client event models - really cool stuff!

Async Operations in WCF: Event Based Model

Along the same lines, I found this gem of a 5 part series on two-way messaging in WCF the other day.  Excellent article - I hope to have a screencast and sample solution of my own concerning Events in WCF before long.

wcf

Manual WCF - An extension

January 18th, 2009

While going through the WCF questions on StackOverflow a few days ago, I found a link to an excellent article on setting up WCF manually from bottom to top written by Miguel A. Castro for Code Magazine.  You can find the article here.  Please go and read it before proceeding.

The thrust of the article is to show how to create a WCF contract, service, host, proxy and client without relying on Visual Studio or other external tools to create anything for you.  In particular Castro prefers to create his own .config files and proxies.

In the article, Castro shows two different ways to set up a client proxy for his service.  The author of the question that lead me to the article had trouble with one of the proxies, shown below:

    <br />using System;    <br />using System.ServiceModel;</p>  <p>namespace CoDeMagazine.ServiceArticle   <br />{    <br />public class AdminClient : IProductAdmin    <br />{    <br />public AdminClient()    <br />{    <br />IProductAdmin productAdminChannel =    <br />new ChannelFactory<iproductadmin>().    <br />CreateChannel();    <br />}</p>  <p>IProductAdmin productAdminChannel = null;</p>  <p>#region IProductAdmin Members</p>  <p>public void UpdateProduct(   <br />ProductData product)    <br />{    <br />productAdminChannel.UpdateProduct(    <br />product);    <br />}</p>  <p>public void DeleteProduct(Guid productID)   <br />{    <br />productAdminChannel.DeleteProduct(    <br />productID);    <br />}</p>  <p>#endregion   <br />}</p>  <p>}   <br />

The problem here is that as far as I can see, I can only get this to work by referencing the endpoint name pointed to by the client. If I change constructor to look like this:

</p>  <p>public AdminClient()   <br />{    <br />IProductAdmin productAdminChannel =    <br />new ChannelFactory<iproductadmin>("endpointName").    <br />CreateChannel();    <br />}    <br />

given an endpoint configuration in the client like:

</p>  <p><endpoint address="<br" />http://localhost:9224/ProductService.svc   <br />binding="wsHttpBinding"    <br />name="endpointName"    <br />contract="CoDeMagazine.ServiceArticle.    <br />IProductBrowser" /></p>  <p>

it works! I’m not sure if Mr Castro is just wrong or if there’s something that I and the other folks on StackOverflow missed.

Either way, I created a sample project to share and a very brief screen cast to go along with it. My example is simpler, but fully working - you shouldn’t have to do any extra work to get it up and running and you can apply the concepts in your own work.

ManualWCFExample

View the screencast here.

I may well have made a goof or error in this post, the code linked, or in the screencast.  If you find something you’d like to correct, feel free to leave a comment below.

Thanks for reading!

screencast, wcf

Clicky Web Analytics