// not sure how "good" this test is ... if it fails at
        // service side, it just results in timeout error.
        // The assertion makes sure that it passes all the tests, but
        // in case it failed, there is almost no hint ...
        public void GetOrCreateSecureMessage()
        {
            bool        passed = false;
            ServiceHost host   = new ServiceHost(typeof(CalcService));
            InterceptorRequestContextHandler handler = delegate(MessageBuffer src)
            {
                Message msg = src.CreateMessage();
                GetOrCreateSecureMessageAtService(msg);
                passed = true;
            };

            try
            {
                SymmetricSecurityBindingElement clisbe =
                    new SymmetricSecurityBindingElement();
                clisbe.ProtectionTokenParameters =
                    new X509SecurityTokenParameters(X509KeyIdentifierClauseType.Thumbprint, SecurityTokenInclusionMode.Never);
                BindingElement transport  = new HttpTransportBindingElement();
                BindingElement sintercept = new InterceptorBindingElement(handler);
                CustomBinding  b_res      = new CustomBinding(clisbe,
                                                              sintercept,
                                                              transport);
                b_res.ReceiveTimeout = b_res.SendTimeout = TimeSpan.FromSeconds(5);
                host.AddServiceEndpoint(typeof(ICalc), b_res, "http://localhost:37564");

                ServiceCredentials cred = new ServiceCredentials();
                cred.ServiceCertificate.Certificate = cert;
                cred.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
                host.Description.Behaviors.Add(cred);

                host.Open();

                ProcessClient();
            }
            finally
            {
                if (host.State == CommunicationState.Opened)
                {
                    host.Close();
                }
            }
            if (!passed)
            {
                Assert.Fail("Didn't pass the interceptor.");
            }
        }
Beispiel #2
0
 public InterceptorBindingElement(InterceptorRequestContextHandler handler)
 {
     this.handler = handler;
 }