如何将WCF服务的操作合约拆分为单个和多个并发模式
我有一个服务 Service A,有 2 个操作合约 CheckServer 和 AddService。由于服务是单例的,并发模式为 Single [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single)]
public Class Service : Iservice
{
public bool CheckService()
{
//Checks server avilabality and returns bool value
}
public int AddService(int a, int b)
{
return int i = a + b;
}
}
这里我的要求是只允许一个 AddService 实例,所以我将其设置为单例。现在 CheckServvice 不一定是单例,所以我如何拆分这 2 个方法实现,使 AddService 成为单例,而 CheckService 成为多个。
提前致谢
I have one service Service A with 2 operation contract CheckServer and AddService. As the Service is singleton with Concurrey mode as Single
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single)]
public Class Service : Iservice
{
public bool CheckService()
{
//Checks server avilabality and returns bool value
}
public int AddService(int a, int b)
{
return int i = a + b;
}
}
Here my requirement is only one Instace of AddService to be allowed, so I made this as singleton. Now CheckServvice is not necessary to be Singleton so how can I split these 2 method implementation to make AddService as singleton and CheckService as multiple.
Thanks in Advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WCF 没有提供您想要的东西。将该逻辑放在 WCF 之外并编写您自己的同步逻辑。例如,实现公开
CheckService
和AddService
的单例类,其中同步将直接在AddService
方法中进行,而CheckService
方法将在免费拨打。制定标准 WCF 每次调用服务,将处理委托给您的单例类。
WCF doesn't provide what you want. Put that logic outside of WCF and write your own synchronization logic. For example implement singleton class exposing
CheckService
andAddService
where synchronization will be directly inAddService
method andCheckService
method will be free to call.Make standard WCF per-call service delegating processing to your singleton class.