none
Pass site minder credentials to WCF service hosted under SSL RRS feed

  • Question

  • Hi,

    I have requirement, wherein i need to authenticate WCF request using SiteMinder Credentials.Have developed client wherein iam using  HttpRequestMessageProperty to pass SM credentials as header.It works good in dev environment where wcf is not under ssl, but when moved to QA where wcf service is hosted under ssl authentication fails.I have set security mode to none and using basichttpbinding.

    Any suggestion would help.

    Thanks

    Wednesday, August 7, 2013 8:43 AM

Answers

  • Hi,

    You said that you are using HttpRequestMessageProperty to pass SM credentials, then please try to refer to the following code:

    using System;
    
    using System.ServiceModel;
    
    using System.ServiceModel.Channels;
    
    using System.Net;
    
    [ServiceContract(Namespace = "http://CustomerSample")]
    
    public interface IMySoapService
    
    {
    
    [OperationContract]
    
    string GetData();
    
    }
     
    class Client
    
    {
    
    static void Main()
    
    {
    
    BasicHttpBinding binding = new BasicHttpBinding();
    
    //need to set AllowCookies to false otherwise our default handling of cookies will stomp all over a manually inserted cookie header
    
    //false is the default
    
    binding.AllowCookies = false;
    
    ChannelFactory<IMySoapService> factory = new ChannelFactory<IMySoapService>(binding, "http://localhost:8000/MySoapService");
    
    IMySoapService channel = factory.CreateChannel();
    
    string tokens = "some siteminder token";
    
    using (OperationContextScope scope = new OperationContextScope((IContextChannel)channel))
    
    {
    
    HttpRequestMessageProperty httprequestMessageProperty = new HttpRequestMessageProperty();
    
    httprequestMessageProperty.Headers.Add(HttpRequestHeader.Cookie, "SMSESSION=" + tokens);
    
    httprequestMessageProperty.Headers.Add(HttpRequestHeader.UserAgent, "SM Client");
    
    OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httprequestMessageProperty);
    
    string data = channel.GetData();
    
    Console.WriteLine(data);
    
    }
    
    ((IChannel)channel).Close();
    
    factory.Close();
    
    Console.WriteLine();
    
    Console.WriteLine("Press to terminate client.");
    
    Console.ReadLine();
    
    }
    
    }
    
     
     
    
    Here is an example server for testing:
    
    
    
    
    
    Code Snippet
    
    using System;
    
    using System.Configuration;
    
    using System.ServiceModel;
    
    using System.ServiceModel.Channels;
    
    using System.Net;
    
    using System.ServiceModel.Description;
    
    [ServiceContract(Namespace = "http://CustomerSample")]
    
    public interface IMySoapService
    
    {
    
    [OperationContract]
    
    string GetData();
    
    }
     
    public class MySoapService : IMySoapService
    
    {
    
    public string GetData()
    
    {
    
    Console.WriteLine("GetData called");
    
    HttpRequestMessageProperty httpRequestMessageProperty =
    
    (HttpRequestMessageProperty)OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name];
    
    Console.WriteLine("Cookie: {0}", httpRequestMessageProperty.Headers[HttpRequestHeader.Cookie]);
    
    Console.WriteLine("UserAgent: {0}", httpRequestMessageProperty.Headers[HttpRequestHeader.UserAgent]);
    
    return "Here's some data";
    
    }
    
    public static void Main()
    
    {
    
     
    
    using (ServiceHost serviceHost = new ServiceHost(typeof(MySoapService)))
    
    {
    
    BasicHttpBinding binding = new BasicHttpBinding();
    
    //need to set AllowCookies to false otherwise our default handling of cookies will stomp all over a manually inserted cookie header
    
    //false is the default
    
    binding.AllowCookies = false;
    
    serviceHost.AddServiceEndpoint(typeof(IMySoapService), binding, "http://localhost:8000/MySoapService");
    
    serviceHost.Open();
    
    Console.WriteLine("The service is ready.");
    
    Console.WriteLine("Press <ENTER> to terminate service.");
    
    Console.WriteLine();
    
    Console.ReadLine();
    
    }
    
    }
    
    }
    

    Best Regards.


    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Marked as answer by lupivj Monday, August 12, 2013 8:30 AM
    Monday, August 12, 2013 3:22 AM
    Moderator