Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi i made a WCF service that uses windows credentials to authenticate the user.

client side i have code like this.

C#
using (var serviceClient = new ServiceClient()) {
    var credentials = new NetworkCredential(username, password);
    serviceClient.ClientCredentials.Windows.ClientCredential = credentials;

    serviceClient.GetData();
}


now i have to do use the client to save data aswell.


The question is how can you reuse the serviceclient or how can you safely store the networkcredentials so the user doesn't have to re login every time the user needs data or updates data to the wcf service?
Posted

Windows credential - as Windows credentials - can only be used if WCF service can identify the client's current Windows credential (means can access the client's domain somehow). In that case client have not pass any credentials implicitly, but the configuration of the server is enough (read here about it[^]).
If you have a WCF service that knows nothing about client's domain you have explicitly pass domain/username/password of current credentials to it, and WCF will authenticate it on it's way...But! In that case you have no way but ask the (human) client to identify himself...
And there is a big problem! As anyone will advise you against to store those info anywhere at all. It may be a better think to add a single credential to your config file, that will be used by every client, that config file can be encrypted to hide values and can be changed if necessary...
 
Share this answer
 
Comments
BELGIUMsky 15-May-14 15:01pm    
first of all i send network credentials to a service that will check against Active Directory
second the user needs to login because the functionality of the program will be depending on the users roles.
i would like to keep the credentials just for the duration of the use of the client application.
else i would need to ask the user his credentials for every transaction with the server
create a static class with static block which runs only once . create an instance of the wcf client object within that static block and keep using that instance.
 
Share this answer
 
Comments
BELGIUMsky 28-May-14 4:29am    
do you need to change the lifespan or something to make this work?
if i try to use the same instance i get an error that the connection is closed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900