简体   繁体   English

在WCF中设计服务和操作

[英]Designing services and operations in WCF

I would appreciate some guidance on modelling services and operations in WCF. 我希望对WCF中的服务和操作建模提供一些指导。

I have a series of business domains, each with bespoke methods that I want to able to use over WCF. 我有一系列业务领域,每个领域都有我想能够在WCF上使用的定制方法。 I guess an OO view would be something like: 我猜OO视图将是这样的:

interface IBusinessDomain1
{
    MyClass1 Method1(...)
    MyClass2 Method2(...)
}

interface IBusinessDomain2
{
    MyClass3 Method3(...)
    MyClass4 Method4(...)
}

My natural inclination was to make each interface a service and each method an operation, the problem I have with this is that operations within individual domains might well need quite different binding configurations. 我的天性是使每个接口成为服务,使每个方法成为操作,我的问题是各个域中的操作可能需要完全不同的绑定配置。 ie Method1 might need to be synchronous, Method2 might need to be asynchronous. 即Method1可能需要同步,Method2可能需要异步。

When definining services and operations for WCF, would a better approach be to think in terms of the data types and the way data needs to be sent? 在为WCF定义服务和操作时,更好的方法是从数据类型和发送数据的方式考虑吗? Perhaps group methods from all business domains that will need to work in a particular way and have those in one service? 也许所有业务领域中的组方法都需要以特定的方式工作并将它们整合到一个服务中? I wonder how other people have tackled similar scenarios? 我不知道其他人如何应对类似的情况?

Most WCF tutorials and examples I have seen tend to use fairly trivial models, often a 'calculator' service offering 'add', 'subtract' etc. operations which all share the same binding. 我见过的大多数WCF教程和示例都倾向于使用比较琐碎的模型,通常是提供“加”,“减”等操作的“计算器”服务,它们都共享相同的绑定。

Some advice on how to approach defining my services and operations would be most appreciated, or just some links to further reading as I cannot find much. 我们将不胜感激关于如何定义我的服务和运营的一些建议,或者由于我找不到太多的建议而只是一些进一步阅读的链接。

Thanks in advance, Will 预先感谢,威尔

I think that grouping your contracts together in regards to whether or not they are called in an asynchronous manner is a bad idea. 我认为,就是否以异步方式调用将合同分组在一起是一个坏主意。 You should still retain the logical groupings for your contracts that make sense. 您仍应保留有意义的合同逻辑分组。

You also need to elaborate on what different binding configurations you might apply to your contracts. 您还需要详细说明您可以对合同应用哪些不同的绑定配置。 If you need to call a method on a contract asynchronously on the client, then that's not something the service has to concern itself with, as the client can choose to generate a contract which supports asynchronous operations (where you will get the Begin* and End* methods on the contract which the channel factory will generate for you). 如果您需要在客户端上异步调用合约上的方法,那么服务就不必担心它了,因为客户端可以选择生成支持异步操作的合约(您将在其中获得Begin *和End *渠道工厂将为您生成的合同中的方法)。

However, if you are doing something like having the service return a token which the client passes back to the service to check on status, you might want to consider a callback interface, as it will make your design much cleaner. 但是,如果您正在做类似让服务返回令牌(客户端将令牌传递回服务以检查状态)的操作,则可能需要考虑回调接口,因为这将使您的设计更加简洁。

If the different binding configurations have to do with changes in the endpoint (ie the transport channel, for example) then you might consider different contracts for different endpoints, but I don't get the impression that is what you are looking for here. 如果不同的绑定配置与端点(例如,传输通道)的更改有关,那么您可能会为不同的端点考虑不同的合同,但我没有得到您在这里寻找的印象。

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

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