我们有一个Web服务,它将请求发送到托管WCF服务进行处理的Windows服务。Windows服务/ WCF和线程,初学者问题
界面简单:
namespace MyApp
{
[ServiceContract]
public interface IMyApp
{
[OperationContract]
string DoSomething(string xml);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
class MyAppWcf : IMyApp
{
public string DoSomething(string xml)
{
Customer customer = GlobalObject.GetCustomer(xml); //millisecs
return customer.DoSomething(xml); //Takes 5-10 seconds
}
}
}
GlobalObject是在WindowsService.OnStart()实例化,并包含所有静态数据的客户对象需要。 界面DoSomething()将被调用到约。 30个不同的客户。
问题:
1.什么是现在的默认线程行为?每次通话都必须等到最后一次通话完成?
2.什么影响会改变InstanceContextMode?
REAL问题:
有多达1000个客户对象,2个不同的客户对象可以被称为并行,但同样缺一不可。例如
DoSomething(“Customer 1”); =>继续。在10秒内回答
DoSomething(“Customer 2”); =>与上述呼叫同时进行。
DoSomething(“Customer 2”); =>将等待DoSomething(“客户2”)的最后一次呼叫完成
我的服务行为设置应该如何,我必须实现锁定机制以防止同时处理多个并行对象?
谢谢。
编辑2:GlobalObject.GetCustomer()只是从字典中检索XML中提到的客户。
感谢马特,那看起来正是我所需要的。 – 2010-11-19 21:27:05