0

I am dealing with a Claim-based application, with the aim to display users info after their authentication through SSO.

For a given authenticated user, I realized a .Net Web Page wherein I show all claims starting from the provided Principal (Page.User), as follows:

public partial class ClaimsPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var claimsPrincipal = Page.User as IClaimsPrincipal;
        if (claimsPrincipal != null)
        {
            IClaimsIdentity claimsIdentity = (IClaimsIdentity) claimsPrincipal.Identity;
            // Something else...
        }
    }
}

And it works fine.

Now, I would like to do the same thing, but by using a .Net Web Service (SOAP), instead of the web page.

My current code is as follows:

[WebService(Namespace = "http://myapp/claims")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class ClaimsWS : System.Web.Services.WebService
{
    [WebMethod]
    public List<ClaimValues> GetClaims()
    {
        // Get Principal..
        // Read claims...
    }
}

My question is: how can I obtain the current Principal inside the WebService body?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
vdenotaris
  • 13,297
  • 26
  • 81
  • 132
  • You are using the ASMX web service technology, which is a legacy technology, and should not be used for new development. WCF or ASP.NET Web API should be used for all new development of web service clients and servers. One hint: Microsoft has retired the [ASMX Forum](http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/threads) on MSDN. – John Saunders Apr 30 '15 at 21:47

1 Answers1

1

Maybe you can try something along these lines. I am returning an Identity object, but you get the claims list from it also.

[WebService(Namespace = "http://myapp/claims")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class ClaimsWS : System.Web.Services.WebService
{
    [WebMethod]
    public List<ClaimValues> GetClaims()
    {
        var principal =ClaimsPrincipal.CreateFromHttpContext(HttpContext.Current); 
        return principal.Claims;
    }
}
Ali Khalid
  • 1,345
  • 8
  • 19