开发者

Sharing a static classes across WCF [duplicate]

开发者 https://www.devze.com 2023-03-01 12:59 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Static Variables in WCF
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Static Variables in WCF

So I am fairly new to using WCF and I have run into the following issue. I have a class which if not using WCF I would have designed it to be a static class, but I am unsure of how to share a static class across WCF. Right开发者_如何学编程 now I am creating a interface named "IMyClass" and which has the ServiceContract attribute which is how I read to share things across WCF. Obviously static classes cannot implement interfaces so am I stuck with a non-static class?


You can still have a static class with static methods that your service implementations call into.

If however you want the service ITSELF to be a singleton service, then you're talking about the InstanceContextMode of Single. This ensures that only one InstanceContext object is used for all incoming calls and is not recycled subsequent to the calls. If a service object does not exist, one is created.

You would configure this by decorating your service implementation like this:

[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
0

精彩评论

暂无评论...
验证码 换一张
取 消