Solved

How to bypass HttpWebRequest default credentials?

Posted on 2011-03-09
1
2,500 Views
Last Modified: 2012-05-11
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!
0
Comment
Question by:develc
1 Comment
 
LVL 11

Accepted Solution

by:
Sudhakar Pulivarthi earned 500 total points
ID: 35093384
Hi

Try only settings the credentials without touching any properties.. It worked for me.
// Provide the WebPermission Credentials
webRequest.Credentials = new NetworkCredential("UserName", "Password");
Dont add to CredentialCache instead set the credential directly to web request object.

Refer this link which helps to understand about credentials
http://blogs.msdn.com/b/buckh/archive/2004/07/28/199706.aspx
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now