How to expose objects through WCF?

后端 未结 4 594
北恋
北恋 2021-01-21 05:32

My project is split up into a typical 3 layer structure for a Silverlight app. That is:

  • A base layer, which is a class library that contains all my business object
4条回答
  •  野的像风
    2021-01-21 06:23

    Sixto's answer is correct. With WCF you can share the BO DLL between the client and the service and re-use those objects (just configure the WCF service reference this way), but this won't work in your case. The issue is that your BO project is a standard .NET project and not a silverlight project.

    Typically I structure my projects a little differently than yours:

    • Common Objects - these would be the data structures marked up with WCF attributes and would also contain any common interfaces such as my data layer interface.
    • Data Access - any data access objects. This references only the common objects and returns those from data calls.
    • Business Logic (optional) - If there are other web services to interface with stick that in its own layer
    • Service - The actual WCF service, references Common directly and other projects through interfaces
    • Silverlight - references the Service

    If you moved your business logic out to its project and just referenced your common "dumb" objects, then you could probably create two logic projects, one silverlight and one standard, and just have the actual files in one and create links to those files in the other. That way you would get the same logic across both projects and it would exist in both Silverlight and standard .NET.

提交回复
热议问题