public void InitializeSinglePolicy(
Type contractType,
ApplicationConfiguration configuration,
BindingFactory bindingFactory,
EndpointConfiguration endpointConfiguration,
List<EndpointDescription> endpoints,
MessageSecurityMode securityMode,
string securityPolicyUri)
{
// allow any url to match.
System.ServiceModel.ServiceBehaviorAttribute behavoir = this.Description.Behaviors.Find<System.ServiceModel.ServiceBehaviorAttribute>();
behavoir.AddressFilterMode = System.ServiceModel.AddressFilterMode.Any;
// specify service credentials
ServiceCredentials credentials = new ServiceCredentials();
credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.Custom;
credentials.ClientCertificate.Authentication.TrustedStoreLocation = StoreLocation.LocalMachine;
credentials.ClientCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck;
credentials.ClientCertificate.Authentication.CustomCertificateValidator = configuration.CertificateValidator.GetChannelValidator();
if (configuration.SecurityConfiguration.ApplicationCertificate != null)
{
X509Certificate2 certificate = configuration.SecurityConfiguration.ApplicationCertificate.Find(true);
if (certificate != null)
{
credentials.ServiceCertificate.Certificate = CertificateFactory.Load(certificate, true);
}
}
this.Description.Behaviors.Add(credentials);
// check if explicitly specified.
ServiceThrottlingBehavior throttle = this.Description.Behaviors.Find<ServiceThrottlingBehavior>();
if (throttle == null)
{
throttle = new ServiceThrottlingBehavior();
throttle.MaxConcurrentCalls = 1000;
throttle.MaxConcurrentInstances = 100;
throttle.MaxConcurrentSessions = 100;
this.Description.Behaviors.Add(throttle);
}
// add the endpoints for each base address.
foreach (Uri baseAddress in this.BaseAddresses)
{
ServiceEndpoint endpoint = null;
// find endpoint configuration.
EndpointDescription description = null;
foreach (EndpointDescription current in endpoints)
{
if (new Uri(current.EndpointUrl) == baseAddress)
{
description = current;
break;
}
}
// skip endpoints without a matching base address.
if (description == null)
{
continue;
}
// set the supported profiles.
description.TransportProfileUri = Profiles.WsHttpXmlOrBinaryTransport;
// create the SOAP XML binding
Binding binding = bindingFactory.Create(baseAddress.Scheme, description, endpointConfiguration);
// add the session endpoint.
endpoint = this.AddServiceEndpoint(contractType, binding, baseAddress, baseAddress);
// set the protection level
if (securityMode == MessageSecurityMode.Sign)
{
endpoint.Contract.ProtectionLevel = System.Net.Security.ProtectionLevel.Sign;
}
// update the max items in graph (set to an low value by default).
foreach (OperationDescription operation in endpoint.Contract.Operations)
{
operation.Behaviors.Find<DataContractSerializerOperationBehavior>().MaxItemsInObjectGraph = Int32.MaxValue;
}
}
}