开发者

wcf and asp.net communication

I am creating an website. It has two web pages. I am trying to pass val开发者_StackOverflowue between the two pages using wcf..

WCF has two functions

static int a;
void send(int b)
  {
    a=b;
  }
int get()
  {
    return a;
  }

class1 creates an object for wcf(say w) and calls w.send(5)

class2 creates an object for wcf(say w1) and calls a= w1.get()

But the value changed by class1 is not getting reflected in class2..


How are you hosting your service?

If your service is hosted in IIS, it is possible that the application was recycled between the 2 calls. In this case the app domain is recreated and the static members loose their values.


By the vary nature WCF is stateless.. What is done by w.send(5) is not known to w1.get() as both the calls are treated as seperate calls.

Either you save the data in some statefull mechanism like (table or file) or else the behavior is as expected.


Though it's static variable but when you create new object it will refer to that particular object only. SO when you are setting value of one variable with one object and getting value from other object then it wont give correct value. So

w.send(5)
a= w1.get()

wont work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜