I have strange problem. I'm calling my web service, hosted on IIS on local intranet. I have several different client programs, which are calling this web service. All programs has the same code to do this. All programs except 1 are working normaly. This,
the newest 1 is acting strangly. When I click the button, to call the web service, i get an error : The request failed with HTTP status 401: Unauthorized.
When I press the button second time it works normal. And so on till I close the program. Next time is the same, on first try i get an error, then works OK.
See this issue is might be with the "System.Net.CredentialCache.DefaultCredentials"
While making the instance of a Web Service kindly do the mentioned below :-
Your_WS_.WS_Method_Name ws = new Your_WS_.WS_Method_Name();
ws.Credentials = System.Net.CredentialCache.DefaultCredentials;
Hope this will work for you.
If this post answered your question or solved your problem, please Mark it as Answer.
jernej72
0 Points
2 Posts
web service returns 401 unauthorized only first time
Aug 29, 2012 11:58 AM|LINK
Hello,
I have strange problem. I'm calling my web service, hosted on IIS on local intranet. I have several different client programs, which are calling this web service. All programs has the same code to do this. All programs except 1 are working normaly. This, the newest 1 is acting strangly. When I click the button, to call the web service, i get an error : The request failed with HTTP status 401: Unauthorized.
When I press the button second time it works normal. And so on till I close the program. Next time is the same, on first try i get an error, then works OK.
Any ideas?
regards
Rajesh Sawan...
Participant
1612 Points
246 Posts
Re: web service returns 401 unauthorized only first time
Aug 29, 2012 12:24 PM|LINK
Hi Friend,
See this issue is might be with the "System.Net.CredentialCache.DefaultCredentials"
While making the instance of a Web Service kindly do the mentioned below :-
Your_WS_.WS_Method_Name ws = new Your_WS_.WS_Method_Name();
ws.Credentials = System.Net.CredentialCache.DefaultCredentials;
Hope this will work for you.
//Happy Coding
Regards,
RajeshS.
jernej72
0 Points
2 Posts
Re: web service returns 401 unauthorized only first time
Aug 29, 2012 12:51 PM|LINK
Hi,
tnx for your reply.
I had set ws credentials to DefaultNetworkCredentials, which i guess is the same as DefaultCredentials or am I wrong?
Anyway, I tried also with DefaultCredentials and result is the same.
Rama Pillai
Member
331 Points
60 Posts
Re: web service returns 401 unauthorized only first time
Dec 07, 2012 11:46 AM|LINK
Hi
Did you find a solution for this? I am having the similar issue here.
I know enabling Anonymous access might solve the issue but the 401 error is coming up only first time and the subsequent calls are fine!
Rama
MCPDEA