I was fighting with this all day long.
I created a WCF service project (the host) and placed the ServiceContract (Interface) in a separate assembly. In another project (the consumer) I referenced that assembly and generated a proxy, with add service reference, and made sure the “reuse types in referenced assemblies” was checked. It then generated the proxy, but not using my handmade interface. To be entirely clear: it is generating an interface, but not using mine from the referenced assembly.
That’s weird, I thought I checked reuse types? So I tried it over and over with different settings, endpoints and cups of coffee, but with no success. So at the end of the day I googled a bit and found out that the “reuse types in referenced assemblies” only applies to DataContracts and not to ServiceContracts! Doh!
So, is it a bug or is it a feature? Well, to me it makes no sense that ServiceContracts don’t get reused, so in my opinion it’s a bug.
What are our options then? Not using the “add service reference”, but doing it manually with a few lines of code, which is also a bit neater:
// Supply the binding and address in code Binding binding = new BasicHttpBinding(); EndpointAddress address = new EndpointAddress("http://tempuri.org/address"); IServiceContract channel = ChannelFactory.CreateChannel(binding, address); // Or read them from the config file ChannelFactory channelFactory = new ChannelFactory(); IServiceContract channel = channelFactory.CreateChannel();