如何在SiteMinder后面调用WCF Http Service

hol*_*see 4 asp.net cookies web-services siteminder

我试图调用在ASP.NET应用程序中托管的WCF 4 Http Web服务.该服务受SiteMinder保护.

我想知道如何以编程方式调用Web服务,更具体地说,我需要传递哪些信息才能在SiteMinder中获得授权以访问我的资源.

我从同一台服务器上运行的ASP.NET应用程序发出请求,因此我可以访问身份验证cookie.

hol*_*see 6

首先获取SiteMinder身份验证令牌,如下所示:

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

然后传递此令牌与您的Web服务调用一样(使用Microsoft.Http.dll):

using Microsoft.Http;
using Microsoft.Http.Headers;
Run Code Online (Sandbox Code Playgroud)

...

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/"))
{ ... }
Run Code Online (Sandbox Code Playgroud)