ISSUE :
 
Profile photo
Submitted by RaKumar
on May 31st, 2011 at 14:26:10 EST

How to add webreference to secure password protected webservice?

I am trying to web reference to a password protected secure webservice using Visual Studio. When I enter the webservice url, it ask me for user credential which I enter it but I am not able to add web reference.
I get error message as:
There was an error downloading 'http://webservicename/Service.asmx?WSDL';.

The request failed with HTTP status 400: Bad Request.


Can anyone please suggest how to add reference to secure password protected webservice using Visual Studio?

I tried in both Visual Stido 2005 and 2010


Profile photo
Replied by SBajra
on May 31st, 2011 at 14:41:59 EST
As far as I know, Visual Studio does not directly allow to add web reference to password protected secure webservice and it will throw error like you have mentioned. But you can still add web reference to secure webservice by using 2 techniques.

1) Browser the webservice wsdl in a browser. It will prompt for security login and provide the username/password. Then save the WSDL xml into a file in your local computer.
Then add web reference to this local version of wsdl. In this way, you will be able to add web reference to secure password protected webservice using visual studio.

2) Browser the webservice wsdl in a browser. It will prompt for security login and provide the username/password. Then save the WSDL xml into a file in your local computer.
Then use wsdl.exe tool to create the proxy class based on locally saved wsdl file.
Syntax to use wsdl.exe tool:
Wsdl /language:language /protocol:protocol /namespace:myNameSpace /out:filename /username:username /password:password /domain:domain <WebServiceUrl or WebServicePath>

More detail on wsdl tool visit:
http://msdn.microsoft.com/en-us/library/d2s8y7bs(v=vs.71).aspx


Important Note:
----------------
However, when you actually make call to this secure webservice, you need to provide NetworkCredential. For this you need to instantiate NetworkCredential class with appropriate user credential.

I hope this helps.
Accepted Answer
Accepted
 Answer

Profile photo
Replied by RaKumar
on May 31st, 2011 at 15:30:45 EST
thanks.

Profile photo
Replied by Mahesh De silva
on May 7th, 2012 at 04:00:59 EST
Hi Thanks for the reply. Really important reply. Can you little bit explain how could i set the network credentials. I am getting the following error

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Digest realm="x_Test_Web_Service", nonce="A89KqG2/BAA=f2e0e423d518e5889d4a856db314362e703caed5", algorithm=MD5, qop="auth"'.

Profile photo
Replied by Shafaqat Ali
on September 27th, 2012 at 03:30:05 EST
How can i do this "Then add web reference to this local version of wsdl"

I cannot see any option to browse this file in visual studio add reference dialog.

Profile photo
Replied by SBajra
on September 27th, 2012 at 10:27:37 EST
Shafaqat Ali:
If you are following option 1, then you first save the wsdl file locally into your hard drive and then you add reference to the local copy of wsdl. When you add web reference in Visual Studio, it will prompt with "URL: ", here you type the local wsdl location for example, c:\mywsdl\mywebservice.wsdl.

Mahesh De silva:
you can add credential using the code.
For example:

MyService.Credentials = new System.Net.NetworkCredential("userID", "password");