?
Solved

How to bypass HttpWebRequest default credentials?

Posted on 2011-03-09
1
Medium Priority
?
2,731 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 2000 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

807 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