WCF Exposing Metadata or having the client implement the interface?

What are the pro / cons to having the client consume a WCF service either via adding a reference to the service (and basically everything is generated for you) or having the client implement a shared interface and them having to code class manually?

Thanks!

Answers


In general, if you don't use code generation, then you'll have to write by hand what would otherwise be generated for you.

The "maintenance issue" that Andrew mentions is solved by simply using "Update Service Reference" when the service contract changes. If this becomes a hassle, then create a separate project to contain all of the proxy classes. You then only need to use "Update Service Reference" in one place.

Of course, if the service contract or related contracts change in an incompatable manner, then your client code will have to change. That's true regardless of which technique you use.


If you generate the code automatically then you have a maintenance issue. You have to regenerate it again whenever you change the interface or any of the server configuration.

For this reason, I NEVER generate the client from exposed metadata.

The interface should be defined in one library. Let's call this library MyContractsLib. The service implementation should be in a separate assembly (which I'll call MyContractsImplementation). The client should go in another assembly.

The client should then use a ChannelFactory to create the service.

        var cf = new ChannelFactory<MyContractsLib.MyContract>(this.EndpointName);
        MyContractsLib.MyContract serviceProxy = cf.CreateChannel();

The only scenario where it's warranted is if the service is developed by a third-party, and you independently writing the client application.

If you have the time and inclination, See this presentation/a goes into this in depth.


Need Your Help

VBA: Loop through criteria in an inactive excel filter?

vba filter criteria

I'm looking for a way to loop through the criteria of an excel filter which doesn't have anything filtered out (ie. all the criteria are enabled). When the filter is active, all the criteria are ad...

Sending account verification email with perl and sendmail/postfix

perl email

For my Perl web application, I need account verification via email.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.