views:

960

answers:

2

i'm new to the WCF service

i have WCF service, in which i use to do file operation to a shared drive. when i try writing/reading to shared location, it throws me a Exception saying "login failure unknown username or bad password"

i can do file operation in code that works fine, the problem is i have moved all the code to WCF service, now i get the above exception.

any help would be greatly appreciated

thanks Vinod

+2  A: 

If when you say WCF service, you mean a windows service which hosts the WCF service. Then I would check the identity of the windows service, if the name and password are written correctly.

If the WCF service is hosted in IIS, then it could be the identity of the application pool or the account acting as the IIS anonymous account.

In both of the above cases it could also be how the WCF service is being called, if you are using windows authentication, make sure that the identity is being set correctly.

Based on your comment it looks like it is the credentials of the logged on user that is trying to access the files. At the same time the files are on a different disk. My best guess is that you are using a user account that does not have access to the file location.

Shiraz Bhaiji
i have hosted in iis 5.1, i'm not sure about the application pool.have set the <identity impersonate="true"/> in web config, Directory security have been set to integrated windows authentication in iis security configuration.i'm able to access the database using couple of my other WCF service, but i have a problem of accessing the shared drive which is in different location. any example would help a lot.thanks
A: 

Vinod, the account used to access the file system is System.Security.Principal.WindowsIdentity.GetCurrent(), check this. If you see ASPNET then you are not impersonated.

 <identity impersonate="true"/>

Has no effect because by default the WCF service don't use the pipeline of ASP.NET (so you don't have access to HttpContext). If it's not what you want turn on the aspnet compatibility as described here.

ASP.NET impersonation: By default, WCF requests always runs as the IIS process identity, even if ASP.NET is set to enable impersonation using System.Web’s configuration option.

Solution :

<system.serviceModel>        
    <serviceHostingEnvironment aspNetCompatibilityEnabled=”true” />    
</system.serviceModel>

There is another way to impersonate the user (Better because it doesn't depend on ASP.NET so no surprise if you decide to use a windows service instead of ASP.NET, but I have not tested), take a look here.

Nicolas Dorier
thanks Slashene! that helped me.