WCF Metadata exposure or client interface?

What are the advantages / disadvantages of using the WCF service by the client, either by adding a link to the service (and basically everything was created for you), or if the client has a shared interface, and they need to enter the code manually?

Thanks!

+4
source share
2 answers

In general, if you are not using code generation, you will have to manually write what would otherwise be created for you.

The "Maintenance Problem" that Andrew mentions is solved simply with the "Update Service" when the service contract is changed. If this becomes a problem, create a separate project containing all proxy classes. Then you only need to use the "Update Service" link in one place.

Of course, if a service contract or related contracts are changed incompatibly, then your customer code will need to change. This is true no matter what method you use.

+2
source

If you automatically generate code, you have a maintenance problem. You must restore it again when you change the interface or any server configuration.

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

An interface must be defined in one library. Call this MyContractsLib library. The service implementation must be in a separate assembly (which I will call MyContractsImplementation ). The client must move to another assembly.

Then the client must use ChannelFactory to create the service.

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

The only scenario in which this is justified is if the service is developed by a third-party organization and you yourself write a client application.

If you have the time and inclination, see this presentation goes in depth.

+2
source

All Articles