Reputation: 125
In the company i work there are 3 teams working on different projects, When it comes to consuming web services between these projects i have a dilemma whether it should be through "Add Service Reference" or we can share the contracts as assemblies and use ChannelFactory to call it ? Any recommended solution or Is there any other better solution than this ?
Upvotes: 4
Views: 1031
Reputation: 649
like for the most questions about software development, it depends :).
If your services are something that keeps your core/business logic and clients are build to make UI for the services i don't see the problem of coupling client and service because purpose of client is to be coupled to some service.
If this is not case and client has wider purpose, and consuming service(s) is just small part of it's functionality than i would think about, considering these factors: - in case of shared contract, you don't have to change/regenerate client in case of Contract changes because it's automatically propagated since both sides are using same types. this has also one more benefit and that is, if something is changed on service side (message field removed/renamed) it will automatically broke build of client and generally whole thing could be fixed faster. otherwise you have to wait first call (or system test) to notify that service has been changed and that something is not ok (with add service reference approach there are ways to achieve this as well).
in some situations you don't want new version of service contract have impact on client code and you want client working (building) independently. in that case generating client would be better approach.
basically answer lies in question are the client and services developed separately or they are part of the same project/application..
and yes, in both situations you can use ChannelFactory
Upvotes: 3
Reputation: 1038730
I'd recommend adding a service reference to generate client proxies instead of sharing contracts as assemblies. It provides weaker coupling between the service and the client. In both cases you could use a ChannelFactory<T>
to invoke the service, it's just that in the first case T
will be generated for you by svcutil.exe
whereas in the second case it will come from the shared assembly.
Upvotes: 2