WCF/WPF best practice - WCF ChannelFactory and PRISM
I'm new to the PRISM framework so my question may be a bit off topic.
I've established a WCF service composed of two projects.
- The WCF .svc and Web.config project just contains the service definitions.
- The service type project that defines the WCF service interface and the service type.
In the client side, I am a little apprehensive as to how I should implement a single, long-lived proxy to the service.
My approach is to create a channel to the service using the ChannelFactory<T> and registering this to the Unity container within my module. This means that my Module must reference the Service Type project to get the service interface (is this the right way?).
The question is "what is the best way to manage this channel when we need to provide authentication to create a channel and how to handle disconnections/re-connections."
The proxy should not be IMO a singleton (or unity-based-singleton) but instead should be created by demand. that way each logical module can create it at will, while not interfering with other modules.
other than that you're approach is very much correct. the proxy should have a reference to the ServiceType project, etc.
if you want to implement an authentication "service", then I would create another Class called AuthenticationService, and register that in Unity as a singleton. This, in turn, would get a reference to a new proxy, and would deal with everything related to authentication/authorazation.
The idea is to let each logic module behave as if it's the only thing in the application, without needing to worry about the other modules other than its dependecies. so this way if you have two Views, each could obtain their own IAuthenticationService, which would be the same (and they shouldn't care about it), while the AuthenticationService itself is dependant on the proxy, and it would hold a reference to it through-out its life.