4

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.

butallmj
  • 1,531
  • 4
  • 14
  • 21
holsee
  • 1,974
  • 2
  • 27
  • 43

1 Answers1

6

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/"))
{ ... }
holsee
  • 1,974
  • 2
  • 27
  • 43
  • The reason I have to Create a Cookie rather than use the Cookie from Request.Cookies["..."] is that they are different .NET Types. – holsee Mar 11 '11 at 10:42