none
WCF References - Reuse of Types from Library References RRS feed

  • Question

  • I self host my WCF Services. So, if I have a Windows Service (A) that has a reference to the WCF Service (B) that has a reference to a library (C). The question is, if I reference a common library in all 3 projects do I get Type Reuse to a separate WCF Service (D) all the way up to A? 

    So, to say it another way, A can execute methods exposed on D.  But, when I pull an object served up by D and that object is in a library that is directly referenced in A should I expect to have Type Reuse?


    Application Developer Manufacturing

    Tuesday, October 4, 2016 4:26 PM

Answers

  • Hello Joel,

    My guess is you are using Add Service Reference to build the proxy in the client.  SVCUTIL does have some support for this and you can take a look at these links:

    • https://philmunro.wordpress.com/2012/01/20/resolving-data-contracts-shared-between-multiple-wcf-services-with-svcutil/
    • https://msdn.microsoft.com/en-us/library/aa347733(v=vs.110).aspx
    • https://blogs.msdn.microsoft.com/youssefm/2009/10/09/reusing-types-in-referenced-assemblies-with-svcutils-r-switch/

    I my experience I find that in larger scale service projects (multi-team), it is often easier to use a contract first approach instead of having clients generate the proxy within their solution.  You could basically do the same thing where you have a single class library with your service contracts initially generated by Add Service Reference or svcutil.  Then after they are generated you can alter them so the shared contracts are collapsed to a single definition.

    Keep in mind that the generated proxy is just a way of letting your solution know how to parse the messages exchanged.  


    Cheers, Jeff

    • Marked as answer by Joel Palmer Friday, October 14, 2016 5:16 PM
    Tuesday, October 4, 2016 8:15 PM

All replies

  • Hello Joel,

    My guess is you are using Add Service Reference to build the proxy in the client.  SVCUTIL does have some support for this and you can take a look at these links:

    • https://philmunro.wordpress.com/2012/01/20/resolving-data-contracts-shared-between-multiple-wcf-services-with-svcutil/
    • https://msdn.microsoft.com/en-us/library/aa347733(v=vs.110).aspx
    • https://blogs.msdn.microsoft.com/youssefm/2009/10/09/reusing-types-in-referenced-assemblies-with-svcutils-r-switch/

    I my experience I find that in larger scale service projects (multi-team), it is often easier to use a contract first approach instead of having clients generate the proxy within their solution.  You could basically do the same thing where you have a single class library with your service contracts initially generated by Add Service Reference or svcutil.  Then after they are generated you can alter them so the shared contracts are collapsed to a single definition.

    Keep in mind that the generated proxy is just a way of letting your solution know how to parse the messages exchanged.  


    Cheers, Jeff

    • Marked as answer by Joel Palmer Friday, October 14, 2016 5:16 PM
    Tuesday, October 4, 2016 8:15 PM
  • This is new to me. I am going to look into this approach to see if it meets my needs. I'm not going to mark this as the answer yet, however because I don't see how it answers my original question.  Maybe it'll be more obvious when I read your links.

    Application Developer Manufacturing

    Wednesday, October 5, 2016 2:08 PM
  • Hi Joel,

    Thanks for suggestion from Jeff.

    >> when I pull an object served up by D and that object is in a library that is directly referenced in A should I expect to have Type Reuse?

    For this scenario, I will reuse types in referenced assemblies to avoid generating new types. If you check reuse types in referenced assemblies, the object will use client reference instead of creating new Service Reference.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, October 6, 2016 2:54 AM
  • This made me dig deeper and I discovered "Contract Equivalency" as the answer to this problem.  Yes, I always reuse types but that goes only skin deep.  After 1 step away from the Service Reference the reuse goes away.  For more information, check out the PluralSight course named "WCF End-to-End" in the "Proxies and Client Configuration" section.

    Application Developer Manufacturing

    Friday, October 14, 2016 5:20 PM