Link to home
Start Free TrialLog in
Avatar of develc
develcFlag for Germany

asked on

How to bypass HttpWebRequest default credentials?

Hi All!

I have a Windows Forms application which requests wcf services from different locations and gets some information from the wsdl. I want to request for credentials by requesting the wsdl file of the services.
My code for the HttpWebRequest:
UriBuilder uriBuilder = new UriBuilder("http://example.com");
            uriBuilder.Query = "WSDL";

            System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uriBuilder.Uri);                        
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Method = "GET";
            webRequest.Accept = "text/xml";

Open in new window



And this is how I tried to avoid the default authentication already (without any success):
System.Net.CredentialCache myCredentialCache = new System.Net.CredentialCache();
            NetworkCredential netCred = new NetworkCredential("user", "password");
            myCredentialCache.Add(new Uri(uriBuilder.Uri.ToString()), "Basic", netCred);
            webRequest.Credentials = netCred;

Open in new window

and:
webRequest.UseDefaultCredentials = false;

Open in new window

and:
webRequest.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequired

Open in new window


I know that some of these is a stupid try, but I don't have any idea. I searched this site for a solution, but found only the ones mentioned above and they aren't working.
Thank you for your help!
ASKER CERTIFIED SOLUTION
Avatar of Sudhakar Pulivarthi
Sudhakar Pulivarthi
Flag of India image

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