예제 #1
0
        public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
        {
            //Find the old requirements and remove
            var requirements = bindingParameters.Find <ChannelProtectionRequirements>();

            bindingParameters.Remove(requirements);

            //Setting the ProtectionLevel at the Service Contract
            if (ProtectionSetting == "None")
            {
                endpoint.Contract.ProtectionLevel = ProtectionLevel.None;
            }
            if (ProtectionSetting == "Sign")
            {
                endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;
            }
            if (ProtectionSetting == "EncryptAndSign")
            {
                endpoint.Contract.ProtectionLevel = ProtectionLevel.EncryptAndSign;
            }

            //create a new set of requirements
            requirements = new ChannelProtectionRequirements();
            bindingParameters.Add(requirements);

            var unprotectedBody = new MessagePartSpecification();
            var protectedBody   = new MessagePartSpecification(true);

            switch (endpoint.Contract.ProtectionLevel)
            {
            case ProtectionLevel.None:
                requirements.OutgoingSignatureParts.AddParts(unprotectedBody, "*");
                requirements.IncomingSignatureParts.AddParts(unprotectedBody, "*");
                requirements.OutgoingEncryptionParts.AddParts(unprotectedBody, "*");
                requirements.IncomingEncryptionParts.AddParts(unprotectedBody, "*");
                break;

            case ProtectionLevel.Sign:
                requirements.OutgoingSignatureParts.AddParts(protectedBody, "*");
                requirements.IncomingSignatureParts.AddParts(protectedBody, "*");

                requirements.OutgoingEncryptionParts.AddParts(unprotectedBody, "*");
                requirements.IncomingEncryptionParts.AddParts(unprotectedBody, "*");
                break;

            case ProtectionLevel.EncryptAndSign:
                requirements.OutgoingSignatureParts.AddParts(protectedBody, "*");
                requirements.IncomingSignatureParts.AddParts(protectedBody, "*");
                requirements.OutgoingEncryptionParts.AddParts(protectedBody, "*");
                requirements.IncomingEncryptionParts.AddParts(protectedBody, "*");
                break;
            }
        }
예제 #2
0
        public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
        {
            var requirements = new ChannelProtectionRequirements();

            var signatureProtectionSpecification = new MessagePartSpecification(_protectionLevel != ProtectionLevel.None);

            requirements.IncomingSignatureParts.AddParts(signatureProtectionSpecification, "*");
            requirements.OutgoingSignatureParts.AddParts(signatureProtectionSpecification, "*");

            var encryptionProtectionSpecification = new MessagePartSpecification(_protectionLevel == ProtectionLevel.EncryptAndSign);

            requirements.IncomingEncryptionParts.AddParts(encryptionProtectionSpecification, "*");
            requirements.OutgoingEncryptionParts.AddParts(encryptionProtectionSpecification, "*");

            bindingParameters.Remove <ChannelProtectionRequirements>();
            bindingParameters.Add(requirements);
            endpoint.Contract.ProtectionLevel = _protectionLevel;
        }