views:

42

answers:

2

I have windows forms app and server side services based on ADO.NET dataservice. Is it a bad practice to create and initialize one static dataservice client in windows app and use it across the program? For example i can use it in all opened forms(which have bindings to service's datacontext's objects) to call SaveChanges() and not loose tracking.. Or creating a service client instance for every new form is better(because i think after some time with one static client there will be huge memory growth)? But when i create a new client for every form, i assume i create a new connection to the service every time..

May be im wrong and a bit confused about using services in client application. Please help me to understand the right way it works.

A: 

Hi,

I would say: It depends. ;) Well your problem is familiar to the decison you have to make, when using directly Entiy Framework. So I recommend you to search for such articles and extract their point.

My own experience with EF tells me, that an application with several workflows should have a context for every workflow. Especially, when more than one workflow can be started at the same time and the user can switch between them. If the application is simple it's proper approach to use only one context.

DHN
The application works with just one workflow..For now there is one context and it works well..But there will be many clients with windows application and i dont know how well it will work then. Thank you for answer.
nihi_l_ist
So you are worried about the service itself not about the client application. Please correct me if I'm wrong.But then I don't understand your post. You have to create at least one connection to the service for every client application which will be started. That's a fact that cannot be avoided. The service will handle it. But I don't know anything about the scalability of WCF DataServices. I think it's good enough for several small and simple client applications.
DHN
I think you understood me right. So the question is: should i create one connection, or many of them in one application..
nihi_l_ist
+1  A: 

Actually the DataServiceContext class doesn't create a connection to the service. The OData protocol it uses is based on REST and as such it's stateless. So creation of the context alone doesn't even touch the service. Each operation (query, save changes) issues a separate and standalone request to the service. From the point of view of the service it's just number of unrelated requests. As noted above it's usually a good idea to have a separate context for each "section" of your application. What is that exactly depends on your app. If you are not going to load/track huge number of entities (1000s at least) then one context might be fine. On the other hand several contexts give you the ability to "cancel" the update operations by simply droping the context and not calling SaveChanges, which might be handy in some applications.

Vitek Karas MSFT
Thank you! Exactly the answer i wanted...I'll read more about OData protocol not to ask such questions without preparation.
nihi_l_ist