Manual WCF - An extension
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.
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!
Add New Comment
Viewing 3 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks
(Trackback URL)