简体   繁体   English

WCF模块化设计应使用什么?

[英]What should I use for a WCF modular design?

Our application is an enterprise application deployed in a distributed environment. 我们的应用程序是部署在分布式环境中的企业应用程序。 It's an ASP.NET MVC 2.0 project connected to a WCF project on another server. 这是一个连接到另一台服务器上的WCF项目的ASP.NET MVC 2.0项目。 What we need is to make our business modules reusable and testable. 我们需要的是使我们的业务模块可重用和可测试。

So what is the best decoupling approach when it comes to WCF? 那么,关于WCF的最佳去耦方法是什么? Is it the Castle Windsor WCF facility? 是温莎城堡WCF设施吗? Or should I use the Common Service Locator approach? 还是应该使用“ 公共服务定位器”方法? And Why? 又为什么呢?

Here's an example of how to create the Execute(string type, string json) method: 这是有关如何创建Execute(string type, string json)方法的示例:

[OperationContract]
public void Execute(string type, string json)
{
    Type commandType = Type.GetType(commandType);

    Type commandHandlerType = typeof(ICommandHandler<>).MakeGenericType(commandType);

    dynamic commandHandler = Bootstrapper.GetInstance(commandHandlerType);

    dynamic command = JsonConvert.DeserializeObject(json, commandType);

    commandHandler.Handle(command);
}

The code sample uses JSON.NET to deserialize the JSON to an object. 该代码示例使用JSON.NET将JSON反序列化为对象。 You can also use the XmlSerializer class if you prefer XML. 如果您更喜欢XML,也可以使用XmlSerializer类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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