Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi folks,

I'm creating a wrapper class (wrapper.dll) for some webservices.
One webservice need basic authentication.

Binding configuration is made in the code, not in app.config.
How can I pass the credentials to the custom binding?

Thanks.
Andy

What I have tried:

C#
internal static CustomBinding BindingSoap12SslBasicAuthentication
        {
            get
            {
                var binding = new CustomBinding()
                {
                    ReceiveTimeout = new TimeSpan(0, 0, 3, 0, 0),
                    SendTimeout = new TimeSpan(0, 0, 2, 0, 0),
                };

                binding.Elements.Add(new TextMessageEncodingBindingElement
                {
                    MessageVersion = MessageVersion.Soap12,
                });

                binding.Elements.Add(new HttpsTransportBindingElement
                {
                    MaxReceivedMessageSize = 50000000,
                    TransferMode = System.ServiceModel.TransferMode.Streamed,
                    AuthenticationScheme=System.Net.AuthenticationSchemes.Basic

                   
                });

               // (Pseudo-Code) Add credentials here...
                binding.Elements.Add(new Credentials
                {
                    user = "MyUser",
                    password = "MyPassword"
                });

                return binding;

            }
        }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900