SgDotNet
Singapore Professional .NET User Group -For Cool Developers

How to deal with "redundant" declarations with WCF clients

Latest post 08-03-2007 10:38 AM by cruizer. 2 replies.
  • 08-01-2007 6:09 PM

    • cruizer
    • Top 50 Contributor
    • Joined on 07-25-2007
    • Singapore
    • Posts 140

    How to deal with "redundant" declarations with WCF clients

    Hi everyone. Pardon this post but I don't exactly know which post category this should belong to.

    Anyway, I've just started working with Windows Communication Foundation (WCF) and I was able to create an IIS-hosted service and it works OK. My question is, when I generate a client using svcutil.exe or the one in VS 2005, it insists on creating declarations for the interfaces and classes I've used for the service. For example, if I have an IShopService interface that I mark with the [ServiceContract] attribute and I have a method in that interface like void AddToCart(Product product) that I mark with the [OperationContract] attribute, the output client code declares IShopService as well as the Product class again.

    Is there a way to avoid this, so that the generated client code can simply make use of my existing IShopService and Product definitions? Normally this shouldn't be an issue for me but since my server (service) code and client code are located in a single VS solution I'm not keen on having duplication.

    Thanks for any help Smile

    http://devpinoy.org/blogs/cruizer
  • 08-03-2007 12:15 AM In reply to

    Re: How to deal with "redundant" declarations with WCF clients

    The "redundant" declarations in WCF clients are required and important if you believe in Service-Orientation.

    One of the four SOA Design Tenets is "Services share schema and contract, not class ".

    (Ref: http://www.soainstitute.org/articles/article/article/the-four-tenets-of-service-orientation.html)

    Assuming that the service (provider) and the client (consumer) belong to different organizations. 

    The service provider is not going to share its class implementation or even interface definitions with its consumer.

    Consumers will just be given the contract (via wsdl or mex) for generating their own client-side proxy in their choice of language/platform.

    That will make the service and the client loosely-coupled.

    Maung Maung
  • 08-03-2007 10:38 AM In reply to

    • cruizer
    • Top 50 Contributor
    • Joined on 07-25-2007
    • Singapore
    • Posts 140

    Re: How to deal with "redundant" declarations with WCF clients

    nice. thanks for that clarification! i realized that too yesterday Stick out tongue that means i can safely declare my DTOs (essentially just data structures) within the assembly for the service and just let the client proxy recreate those DTOs on the client side based on the contract/WSDL. Yes
    http://devpinoy.org/blogs/cruizer
Page 1 of 1 (3 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems