WCF Service Client Lifetime
Posted
by Burt
on Stack Overflow
See other posts from Stack Overflow
or by Burt
Published on 2010-03-14T00:00:58Z
Indexed on
2010/03/14
0:05 UTC
Read the original article
Hit count: 528
wcf
|wcf-client
I have a WPF appliction that uses WCF services to make calls to the server.
I use this property in my code to access the service
private static IProjectWcfService ProjectService
{
get
{
_projectServiceFactory = new ProjectWcfServiceFactory();
return _projectServiceFactory.Create();
}
}
The Create on the factory looks like this
public IProjectWcfService Create()
{
_serviceClient = new ProjectWcfServiceClient();
//ToDo: Need some way of saving username and password
_serviceClient.ClientCredentials.UserName.UserName = "Brendan";
_serviceClient.ClientCredentials.UserName.Password = "password";
return _serviceClient;
}
To access the service methods I use somethingn like the following.
ProjectService.Save(dto);
Is this a good approach for what I am trying to do? I am getting an errorthat I can't track down that I think may be realted to having too many service client connections open (is this possible?) notice I never close the service client or reuse it.
What would the best practice for WCF service client's be for WPF calling?
Thanks in advance...
© Stack Overflow or respective owner