How to bypass ADFS authentication for a WCF service hosted within the mvc 2 application?

Posted by Santosh.Impossible under WCF on 7/30/2014 | Points: 10 | Views : 1168 | Status : [Member] | Replies : 0
Hi WebGurus,

I have a WCF service hosted within a mvc2 application. The application uses ADFS as authentication process. Now I am trying to check the status of the WCF service (i.e running and up or not) using the below code without authenticating against the application:

Site URL :
WCF Address:

Based on the above details _address =


var passed = Utility.ConnectToWebService(_address, out statusCode, out responseText);
public static bool ConnectToWebService(Uri address, out System.Net.HttpStatusCode statusCode, out string responseText)
System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => { return true; };

System.Net.HttpWebRequest request =

// Set some reasonable limits on resources used by this request
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;

// use default credentials
request.Credentials = System.Net.CredentialCache.DefaultCredentials;

System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();

statusCode = response.StatusCode;

// Get the stream associated with the response.
System.IO.Stream receiveStream = response.GetResponseStream();

// Pipes the stream to a higher level stream reader with the required encoding format.
System.IO.StreamReader readStream = new System.IO.StreamReader(receiveStream, System.Text.Encoding.UTF8);

responseText = readStream.ReadToEnd();

System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => { return false; };

return statusCode == System.Net.HttpStatusCode.OK;

While debugging the code I see that the ResponseUri value of the response object has ADFS url embedded to it which shows that it is going to ADFS to authenticate.

Can anyone help me to show the best way to bypass the ADFS authentication while checking the WCF service status?

Thanks & Regards,
Santosh Kumar Patro

santosh kumar patro


(No response found.)

Login to post response