0

I've build wcf service under IIS 7.

I've problem with shared data.

I get error in runtime, when i try to access static data from other service.

Service 1

[ServiceContract(Name="ServiceChat", CallbackContract=typeof(IChatCallback))]
public ChatService { 
     static int counter;
     ...
}

Service 2

[ServiceContract(Name="ServiceAvatar", CallbackContract=typeof(IAvatarCallback))]
public AvatarService {
     [OperationContract] 
     public int Test {
          return ChatService.counter; // Throw error
     }
     ...
}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Hensembryan
  • 1,067
  • 3
  • 14
  • 31

1 Answers1

0

As per my understanindg . You want to share a centralized static data among different resourses.

Why dont you decorate your WCF contract with [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]

This will create only one session and all the clients are accessing your services through the same session.

So its like they all get the same source .

Hope this helps.

Tabish Sarwar
  • 1,505
  • 1
  • 11
  • 18