Using SAML token with Web Service (wsdl)

浪子不回头ぞ 提交于 2019-12-20 07:28:52

问题


I have been given a .wsdl file and .pfx from the provider.

I call the IdP and acquire a SAML token. Now I need to pass that token to the WebService.

How do I use the SAML token to work with the WebService?

I am using .NET 4.5


回答1:


I was able to add the token and get response with the help of the following two posts:

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

Here's my code:

  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
        }
    }



回答2:


This is something that should be specified by the provider of the WS. A common standard i the WS-security standard by OASIS

Using this standard the SAML Assertion is placed in a SOAP security header



来源:https://stackoverflow.com/questions/26857808/using-saml-token-with-web-service-wsdl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!