与WCF服务共享的变量 [英] Shared variable with wcf service

查看:153
本文介绍了与WCF服务共享的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

有什么办法可以在wcf上共享变量?

示例:

我有这样的wcf服务:

Hi every body,

is there any way to share a variable on wcf?

Example:

I''ve a wcf service like this:

[ServiceContract]
interface Iwcfservice
{
     [ContractOperation]
     void method1();

     [ContractOperation]
     void method2();
}

class wcfservice : Iwcfservice
{
     public void method1()
     {
     }

     public void method2()
     {
     }
}



现在,我希望method1()和method2()使用共享变量.我怎样才能做到这一点?据我所知,method1()和method2()将在两个线程中调用.



Now, i would like method1() and method2() to use a shared variable. How can i do that? According to my knowledge, method1() and method2() will be called in two thread.

推荐答案

尝试以单实例模式运行Web服务.
有关详细信息,请参见 3种执行WCF实例管理的方法(每次调用,每次会话和单个) [ ^ ].
Try running your web service in a single instance mode.
For details, see 3 ways to do WCF instance management (Per call, Per session and Single)[^].


您好,
您可以简单地在 Iwcfservice 接口中使用自定义属性.例如:
Hi,
You can simply use custom properties in your Iwcfservice Interface. For example:
[ServiceContract]
interface Iwcfservice
{
     [ContractOperation]
     void method1();
 
     [ContractOperation]
     void method2();
 int Count { get; set; } // Property interface
 string Name { get; set; } // Property interface 

}


这篇关于与WCF服务共享的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆