【发布时间】:2014-01-29 14:58:24
【问题描述】:
我有一个 ASP.NET 应用程序,它使用“服务参考”来连接第三方/非现场支付处理器。 我从支付处理器下载的示例代码包括以下内容:
public class SoapAPIUtilities{
private static CustomerProfileWS.Service service = null;
public static CustomerProfileWS.Service Service{
get{
if(service == null){
service = new CustomerProfileWS.Service();
}
return service;
}
}
}
我生成CustomerProfileWS.Serviceautomatically using Visual Web Developer:它的自动生成实现是ServiceModel.ClientBase的子类的子类,它
MSDN 文档为“不保证任何实例成员都是线程安全的”。
要从 ASP.NET 页面使用此服务,我想我需要对服务进行线程安全的访问,而以上不是?
- this question 的答案说它是线程安全的
- 但是the end of this MSDN page 说它不是线程安全的?
如果它不是线程安全的,那么让它成为线程安全的更好方法是什么:
- 包装一个访问器类,该类在静态单例 (e.g. as shown here) 周围实现锁定?
- 不要使用静态单例;而是根据需要创建多个/临时
CustomerProfileWS.Service实例,作为需要它们的 ASP.NET 页面方法中的局部变量?
【问题讨论】:
标签: asp.net wcf web-services thread-safety authorize.net