将SAML令牌与Web服务一起使用(wsdl)

时间:2014-11-11 05:00:40

标签: asp.net web-services wcf wsdl saml

我从提供商处获得了.wsdl文件和.pfx。

我调用IdP并获取SAML令牌。现在我需要将该令牌传递给WebService。

如何使用SAML令牌处理WebService?

我正在使用.NET 4.5

2 个答案:

答案 0 :(得分:1)

我可以在以下两个帖子的帮助下添加令牌并获得回复:

http://www.noiseworks.org/security-token-service-in-asp-net-application-part-2/ http://travisspencer.com/blog/2012/01/cryptographic-operations-are-r.html

这是我的代码:

  private static string serviceEndpoint = "https service endpoint";
    public static void CallProviderService(SecurityToken token)
    {
        var binding = new WS2007FederationHttpBinding(WSFederationHttpSecurityMode.TransportWithMessageCredential);
        binding.Security.Message.EstablishSecurityContext = false;
        binding.Security.Message.IssuedKeyType = SecurityKeyType.BearerKey;

        var channelFactory = new ChannelFactory<ISomeProviderService>(binding, new EndpointAddress(new Uri(serviceEndpoint)));
        string thumb = "mycertthumbprint";
        channelFactory.Credentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindByThumbprint, thumb);
        channelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.PeerOrChainTrust;
        channelFactory.ConfigureChannelFactory();
        channelFactory.Credentials.SupportInteractive = false;

var elements = service.Endpoint.Binding.CreateBindingElements();
elements.Find<SecurityBindingElement>().EnableUnsecuredResponse = true;
service.Endpoint.Binding = new CustomBinding(elements);

        var channel = channelFactory.CreateChannelWithIssuedToken<ISomeProviderService>(token);

        try
        {
            var response = channel.MyServiceMethod(somedataobject);
        }

        catch (Exception ex)
        {
           //log message
        }
    }

答案 1 :(得分:0)

这应该由WS的提供者指定。 OASIS的WS-security标准的通用标准

使用此标准,SAML断言放在SOAP安全标头