I have an ASP.NET application, which uses a 'service reference' to a 3rd-party/offsite payment processor. The sample code which I downloaded from the payment processor includes the following:
public class SoapAPIUtilities{
private static CustomerProfileWS.Service service = null;
public static CustomerProfileWS.Service Service{
get{
if(service == null){
service = new CustomerProfileWS.Service();
}
return service;
}
}
}
I generate CustomerProfileWS.Service
automatically using Visual Web Developer: its auto-generated implementation is a subclass of subclass of ServiceModel.ClientBase, which
MSDN documents as, "Any instance members are not guaranteed to be thread safe".
To use this service from ASP.NET pages, I guess I need to make access to the service thread-safe, which the above is not?
- The answers to this question say that it is thread-safe
- But the end of this MSDN page says that it is not thread-safe?
If it is not thread-safe then what is the better way to make it thread-safe:
- Wrap an accessor class which implements a lock around the static singleton (e.g. as shown here)?
- Don't use a static singleton; instead create multiple/temporary
CustomerProfileWS.Service
instances as needed, as local variables in methods of the ASP.NET pages which need them?