Solved

How to bypass HttpWebRequest default credentials?

Posted on 2011-03-09
1
2,550 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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