简体   繁体   中英

Avoid exposing too many assemblies to client consuming WCF service

I need a bit of guidance here. I have a WCF service that is part of a larger solution. Currently, too many assemblies must be referenced by an end-consumer due to inheritance issues. For example, here is my basic project setup:

MyProject.Domain

namespace MyProject.Domain
{
    public interface IFooable{}

    public class Foo : IFooable{}
}

MyProject.Contracts

namespace MyProject.Contracts
{
    [DataContract]
    public class FooData : IFooable{}

    [ServiceContract]
    public class IFooService
    {
        IEnumerable<FooData> GetFoos();
    }
}

MyProject.Proxies

namespace MyProject.Proxies
{
    public class WCFClient{}
}

The problem lies here:

class ConsumerCode
{
    private WCFClient = new WCFClient();

    void consumeService()
    {
        // Compiler error. No reference to MyProject.Domain.IFooable
        var foos = WCFClient.GetFoos();
    }

That means an end-consumer who uses the FooData object will have to also include a reference to MyProject.Domain , which stinks because I shouldn't have to expose the Business Logic Layer to the end-client of a WCF service.

Is there a way around this?

Its pretty straightforward- define IFooable in Contracts, not in Domain.

The logic here is that anything that is exposed to the client is (by definition) a contract or part of a contract, not a domain entity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM