Пример #1
0
        /// <summary>
        /// Returns a custom wcf binding that will create a SOAP request
        /// compatible with the Simple Order API Service
        /// </summary>
        protected static CustomBinding getWCFCustomBinding(Configuration config)
        {
            //Setup custom binding with HTTPS + Body Signing
            CustomBinding currentBinding = new CustomBinding();

            //Sign the body
            AsymmetricSecurityBindingElement asec = (AsymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateDuplexBindingElement(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10);

            asec.SetKeyDerivation(false);
            asec.IncludeTimestamp        = false;
            asec.EnableUnsecuredResponse = true;
            asec.SecurityHeaderLayout    = SecurityHeaderLayout.Lax;

            if (config.UseSignedAndEncrypted)
            {
                asec.LocalClientSettings.IdentityVerifier = new CustomeIdentityVerifier();
                asec.RecipientTokenParameters             = new System.ServiceModel.Security.Tokens.X509SecurityTokenParameters {
                    InclusionMode = SecurityTokenInclusionMode.Once
                };
                asec.MessageProtectionOrder = System.ServiceModel.Security.MessageProtectionOrder.SignBeforeEncrypt;
                asec.EndpointSupportingTokenParameters.SignedEncrypted.Add(new System.ServiceModel.Security.Tokens.X509SecurityTokenParameters());
                asec.SetKeyDerivation(false);
            }

            //Use custom encoder to strip unsigned timestamp in response
            CustomTextMessageBindingElement textBindingElement = new CustomTextMessageBindingElement();


            //Setup https transport
            HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement();

            httpsTransport.RequireClientCertificate = true;
            httpsTransport.AuthenticationScheme     = AuthenticationSchemes.Anonymous;
            httpsTransport.MaxReceivedMessageSize   = 2147483647;
            httpsTransport.UseDefaultWebProxy       = false;

            //Setup Proxy if needed
            if (mProxy != null)
            {
                WebRequest.DefaultWebProxy        = mProxy;
                httpsTransport.UseDefaultWebProxy = true;
            }


            //Bind in order (Security layer, message layer, transport layer)
            currentBinding.Elements.Add(asec);
            currentBinding.Elements.Add(textBindingElement);
            currentBinding.Elements.Add(httpsTransport);
            return(currentBinding);
        }
        /// <summary>
        /// Returns a custom wcf binding that will create a SOAP request
        /// compatible with the Simple Order API Service
        /// </summary>
        protected static CustomBinding getWCFCustomBinding()
        {
            //Setup custom binding with HTTPS + Body Signing
            CustomBinding currentBinding = new CustomBinding();

            //Sign the body
            AsymmetricSecurityBindingElement asec = (AsymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateDuplexBindingElement(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10);

            asec.SetKeyDerivation(false);
            asec.IncludeTimestamp        = false;
            asec.EnableUnsecuredResponse = true;
            asec.SecurityHeaderLayout    = SecurityHeaderLayout.Lax;

            //Use custom encoder to strip unsigned timestamp in response
            CustomTextMessageBindingElement textBindingElement = new CustomTextMessageBindingElement();


            //Setup https transport
            HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement();

            httpsTransport.RequireClientCertificate = true;
            httpsTransport.AuthenticationScheme     = AuthenticationSchemes.Anonymous;
            httpsTransport.MaxReceivedMessageSize   = 2147483647;
            httpsTransport.UseDefaultWebProxy       = false;

            //Setup Proxy if needed
            if (mProxy != null)
            {
                WebRequest.DefaultWebProxy        = mProxy;
                httpsTransport.UseDefaultWebProxy = true;
            }


            //Bind in order (Security layer, message layer, transport layer)
            currentBinding.Elements.Add(asec);
            currentBinding.Elements.Add(textBindingElement);
            currentBinding.Elements.Add(httpsTransport);
            return(currentBinding);
        }