Solved

How to bypass HttpWebRequest default credentials?

Posted on 2011-03-09
1
2,567 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

756 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