Search code examples
asp.netweb-servicescookiessiteminder

How to call WCF Http Service behind SiteMinder


I am trying to call WCF 4 Http Web Services which are hosted within an ASP.NET application. The Service is protected behind SiteMinder.

I was wondering how I could programmatically call the web service, and more specifically what information will I need to pass to be authorized within SiteMinder to access my resources.

I am making the request from the ASP.NET application running on the same server, so I have access to the authentication cookie.


Solution

  • First obtain the SiteMinder authentication token like so:

        private string ObtainSiteMinderSession()
        {
            var cookie = Request.Cookies["SMSESSION"];
            return cookie != null ? cookie.Value : string.Empty;
        }
    

    Then pass this token as with your web service calls like so (using Microsoft.Http.dll):

    using Microsoft.Http;
    using Microsoft.Http.Headers;
    

    ...

    var Client = new HttpClient(baseUri);
    
    // Add SMSESSION
    var smCookie = new Cookie();
    smCookie.Add("SMSESSION", ObtainSiteMinderSession());
    Client.DefaultHeaders.Cookie.Add(smCookie);
    
    using (var httpRequest = new HttpRequestMessage(Verbs.GET, "/LoadData/"))
    { ... }