How do you supply a type that's defined in a web service to another web service (share types)?

后端 未结 1 541
说谎
说谎 2020-12-21 05:20

I\'ve got 2 WCF services. Service A contains the definition of the type MyEntity. Service B contains a service reference to Service A and therefore can use the type for MyEn

相关标签:
1条回答
  • 2020-12-21 05:48

    Sounds like you are using service references by way of Visual Studio's Add Service Reference command. While adequate, it can arguably become troublesome in medium to large projects due to:

    1. Service types are re-defined in the client rather than using a common library (as you have discovered).

    2. When a service contract changes, this will generally cause the service to be updated but not so in the client because of point 1. Client proxies become stale overtime as the schema evolves. You have to refresh reference

    My best suggestion is not to use Add Service Reference and roll your client proxies by hand.

    Once performed you will have additional libraries:

    1. A.Contracts.dll - here you define all the service interfaces and data models for service A
    2. B.Contracts.dll - here you define all the service interfaces and data models for service B
    3. Common.Contracts.dll - If A & B have common types, place them here. (canonical data models)
    4. A.Service.dll - service A implementation
    5. B.Serivce.dll - service B implementation
    6. ClientProxies.dll - roll-your-own client proxies for all your services

    You don't have to implement all of the above now. All that is required is the manual ClientProxies.dll and you can always iterate to the rest later as required.

    More

    • Tell me more about WCF the Right Way in my other SO answer
    0 讨论(0)
提交回复
热议问题