4

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!

2
  • See this similar question. Amusingly, it's the same two people answering. stackoverflow.com/questions/3697181/help-debugging-wcf Commented Dec 2, 2010 at 3:09
  • I think both answers are correct in different scenarios. For my particular scenario and becuase I have to choose one correct answer I am going to go with using the WSDL Commented Dec 2, 2010 at 14:16

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I having auto-generated proxy classes in a separate library feasible? When you generate a service reference, it generates both the proxy class and entries in your app.config file. If you get the proxy classes without the app.config file entries, aren't you getting only half the benefit? (Mind you, I'm advocating that you do everything by hand) anyway).
@Andrew: the app.config issue is identical for every component that puts things into app.config: you always have to copy the config entries from the app.config of the library into the app (or web).config of the application. Always.
2

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 goes into this in depth.

5 Comments

so, what do you do when the interface changes and you're not using "Add Service Reference"?
@John: The client and the service implementation should be reading the interface from the same file. I'll add that to my answer.
so you still have the same issue when the change is incompatible, and you have to make sure your build system is referencing the correctly-updated version of the assembly containing the contracts, and it's just not that different from maintaining a "current" instance of the service and using "Update Service Reference". You'll need a deployed instance of the service for non .NET clients in any case.
@John: The scenario I'm specifically thinking of is where the contract definition, the service definition and the client are all in the same solution. If you are linking to libraries that are being updated in a different solution then I would say that's equivalent to the service generated by a third party.
just to be clear: that's not very SOA. The clients and services are quite tightly coupled in this scenario.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.