Beispiel #1
0
      public static Binding CreateMultiFactorAuthenticationBinding()
      {
          HttpsTransportBindingElement httpTransport = new HttpsTransportBindingElement();

          httpTransport.MaxReceivedMessageSize = int.MaxValue;


          //AddressHeader addressHeader = AddressHeader.CreateAddressHeader("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", security, xmlObjectSerializer);


          CustomBinding binding = new CustomBinding();

          binding.Name = "myCustomBinding";

          TransportSecurityBindingElement messageSecurity = TransportSecurityBindingElement.CreateUserNameOverTransportBindingElement();

          messageSecurity.IncludeTimestamp = false;

          messageSecurity.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12;
          messageSecurity.SecurityHeaderLayout   = SecurityHeaderLayout.Strict;
          messageSecurity.SetKeyDerivation(false);
          TextMessageEncodingBindingElement Quota = new TextMessageEncodingBindingElement(MessageVersion.Soap11, System.Text.Encoding.UTF8);

          Quota.ReaderQuotas.MaxDepth = 32;
          Quota.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
          Quota.ReaderQuotas.MaxArrayLength         = 16384;
          Quota.ReaderQuotas.MaxBytesPerRead        = 4096;
          Quota.ReaderQuotas.MaxNameTableCharCount  = 16384;


          binding.Elements.Add(Quota);
          binding.Elements.Add(messageSecurity);
          binding.Elements.Add(httpTransport);
          return(binding);
      }
Beispiel #2
0
        public static CollateralRegistrationSearchService2016Client CreatePPSRClient(string url,
                                                                                     string username,
                                                                                     string password, UrlType urlType)
        {
            CustomBinding binding = new CustomBinding();

            var security = TransportSecurityBindingElement.CreateUserNameOverTransportBindingElement();

            security.IncludeTimestamp       = false;
            security.DefaultAlgorithmSuite  = SecurityAlgorithmSuite.Basic256;
            security.MessageSecurityVersion = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
            MessageEncodingBindingElement encoding = null;

            if (urlType == UrlType.MTOM)
            {
                encoding = new MtomMessageEncodingBindingElement();
                encoding.MessageVersion = MessageVersion.Soap11;
            }
            else
            {
                encoding = new TextMessageEncodingBindingElement();
                encoding.MessageVersion = MessageVersion.Soap11;
            }

            var transport = new HttpsTransportBindingElement();

            transport.MaxReceivedMessageSize = 20000000; // 20 megs

            binding.Elements.Add(security);
            binding.Elements.Add(encoding);
            binding.Elements.Add(transport);

            CollateralRegistrationSearchService2016Client client = new CollateralRegistrationSearchService2016Client(binding,
                                                                                                                     new EndpointAddress(url));

            // to use full client credential with Nonce uncomment this code:
            // it looks like this might not be required - the service seems to work without it
            // client.ChannelFactory.Endpoint.Behaviors.Add(new InspectorBehavior());
            client.ChannelFactory.Endpoint.Behaviors.Remove <System.ServiceModel.Description.ClientCredentials>();
            client.ChannelFactory.Endpoint.Behaviors.Add(new CustomCredentials());

            client.ClientCredentials.UserName.UserName = username;
            client.ClientCredentials.UserName.Password = password;

            return(client);
        }
        static void Main(string[] args)
        {
            try
            {
                //for invalid ssl server certificate
                System.Net.ServicePointManager.ServerCertificateValidationCallback +=
                    (se, cert, chain, sslerror) =>
                {
                    return(true);
                };

                CustomBinding binding  = new CustomBinding();
                var           security = TransportSecurityBindingElement.CreateUserNameOverTransportBindingElement();
                security.IncludeTimestamp        = true;
                security.DefaultAlgorithmSuite   = SecurityAlgorithmSuite.Basic256;
                security.MessageSecurityVersion  = MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;
                security.EnableUnsecuredResponse = true;
                var encoding = new TextMessageEncodingBindingElement();
                encoding.MessageVersion = MessageVersion.Soap11;
                var transport = new HttpsTransportBindingElement();
                transport.MaxReceivedMessageSize = 2000000;
                binding.Elements.Add(security);
                binding.Elements.Add(encoding);
                binding.Elements.Add(transport);
                WSClient.Proxy.TargetWS client = new Proxy.TargetWS(binding,
                                                                    new EndpointAddress(Properties.Settings.Default.Url));
                //change credential for the custom credentials instance
                client.ChannelFactory.Endpoint.Behaviors.Remove <System.ServiceModel.Description.ClientCredentials>();
                client.ChannelFactory.Endpoint.Behaviors.Add(new CustomCredentials());
                client.ClientCredentials.UserName.UserName = Properties.Settings.Default.username;
                client.ClientCredentials.UserName.Password = Properties.Settings.Default.password;
                Proxy.Message message = new WSClient.Proxy.Message();
                message.id = "whatever";
                client.foo(message);
                System.Console.Write("Success");
            }
            catch (Exception ex)
            {
                System.Console.Write(ex.Message);
            }
        }