1. [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
该属性用来控制Service创建的控制模式,PerCall 表示每次来一个请求为其创建一个对象的实例,PerSession是每次一个请求来只创建一个该服务对象的实例直至其销毁,Single表示只允许创建一个该服务的实例。
其中InstanceContextMode:
public enum InstanceContextMode
{
PerSession = 0,
PerCall = 1,
Single = 2,
}
2.使用此属性如下:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class BrandPartnerProductsService : IBrandPartnerProductsService{}
3.Restful WCF中的服务必须加上此属性:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
例如:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class BrandPartnerProductsService : IBrandPartnerProductsService{}