在WCF中设计服务和操作

时间:2022-12-25 20:31:03

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. I guess an OO view would be something like:

我有一系列业务域,每个域都有我希望能够在WCF上使用的定制方法。我猜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. i.e. 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? 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?

在为WCF定义服务和操作时,更好的方法是考虑数据类型和数据需要发送的方式吗?也许来自所有业务领域的组方法需要以特定方式工作并将这些方法集中在一个服务中?我想知道其他人是如何处理类似情况的?

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

先谢谢,威尔

1 个解决方案

#1


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 (i.e. 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.

如果不同的绑定配置与端点中的更改(例如,传输通道)有关,那么您可能会考虑针对不同端点的不同合同,但我不会得到您在此处寻找的印象。

#1


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 (i.e. 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.

如果不同的绑定配置与端点中的更改(例如,传输通道)有关,那么您可能会考虑针对不同端点的不同合同,但我不会得到您在此处寻找的印象。

相关文章