在内存和WCF服务之间切换?

时间:2011-07-21 15:04:39

标签: wcf optimization

想象一下,我有以下标准WCF代码:

[ServiceContract]
interface ICustomerService {
    [OperationContract]
    Customer GetCustomer();
}

public ICustomerService {
     public Customer GetCustomer() 
     { 
          return MyStore.WhatIsNeeded();
     }
}

这很好用,可以让我分发服务和消费代码。

如果在一个盒子里工作,完全绕过WCF引擎是否可能(并且是一个好主意)?

事实上,我希望该应用能够在服务器场服务器或小型单机服务器上运行。

为了降低WCF消息传递成本,我希望有类似的内容:

ICustomerService service = null;
if(singlebox)
{
    service = new CustomerService(); // Direct instanciation of the service class. No WCF here ...
}
else
{
    service = new CustomerServiceClient(); // Wcf client
}

var cust = service.GetCustomer();

如果包装得当,这种技术可以降低服务器费用吗?

2 个答案:

答案 0 :(得分:1)

这不起作用,因为客户端将尝试访问不再公开服务的服务的端点。服务和客户端都需要WCF管道。对于单机方案,请查看NetNamedPipeBinding,它是通过等效共享内存完成的WCF管道。

答案 1 :(得分:0)

这肯定会减少WCF运行时的开销。我将创建一个工厂类,它将检查是否(单一框)和新的正确的ICustomerService实现。