Link to home
Start Free TrialLog in
Avatar of dkilby
dkilbyFlag for Canada

asked on

ASP.NET + Impersonating in Web Service

We have a webservice that exposes a public method with SoapDocumentMethod(OneWay:=True).  What is the identity it's using to process?  Web.config for the web service is set to imporsonate identity impersonate="true" userName="<username>" password="<password>" but it's not using it.

Keep getting the following error: Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.

If i remove SoapDocumentMethod(OneWay:=True) it seems to work, the reason i want this is i don't want the application to wait for the webservice to finish.
Avatar of ihenry
ihenry

The error you're getting might be due to a problem with the SQL Server not being able to authenticate your web service security context and happens when the SQL Server is running on different machine. Can you explain a little bit more about IIS authentication method used? and it would be more helpful if you can print out the web service security context identity name so that you can tell what user account is actually being authenticated to the SQL Server.
Avatar of dkilby

ASKER

Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=<database>;Data Source=<server>;Connect Timeout=1800;

the imperosonation is in the web.config

SQL Server is running on a different machine,  the thing i don't understand is if i remove SoapDocumentMethod(OneWay:=True) it seems to work.
Can you post here the exception stack trace?
Avatar of dkilby

ASKER

From doing some other research it seems that the webservice is not reading the web.config, so if the webservice doesnt have access to HttpContext how else can it impersonate??
are you using .NET Framework version 1.0?
Avatar of dkilby

ASKER

Using v1.1.4322

Here is the error

Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
DEVELOPMENT server connection string:Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=testDB_Dev;Data Source=sqlmachine;Connect Timeout=1800; Context Identity:  
Let me guess, code in your webmethod is trying to connect to database with a connection string supplied from web.config. Do some debugging and check if you're able to get the connection string in the first place. Then, before open a connection to database print out Thread.CurrentPrincipal.Identity.Name and see what's the value.
Avatar of dkilby

ASKER

but the connection string is showing up in the connection string
I find your problem is weird since SoapDocumentMethodAttribute is unlikely to cause this kind of problem. Just need some more information, is the SQL Server in the same domain with your Web Server? are you login with domain account? and is your login account is enabled for delegation?
Avatar of dkilby

ASKER

the sql server is on the same domain as the web server, i am logged in with domain account if the webservice can read the web.config file

The most confusing part is why it won't read the web.config when i have SoapDocumentMethod(OneWay:=True), i just tried running the app without it and it inserted data into the database no problem, as soon as i put it back i get the error.
ASKER CERTIFIED SOLUTION
Avatar of ihenry
ihenry

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am bit curious to know why you are choosing this SoapDocumentMethod ?
SoapDocumentMethod will help your webservice to fire-and-forget kind of job.

Also can I know which WSE you are using ?Which version?

Sachi