UniqueContractNameValidationBehavior.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Dispatcher
  5. {
  6. using System.ServiceModel.Channels;
  7. using System.ServiceModel;
  8. using System.ServiceModel.Description;
  9. using System.Collections.ObjectModel;
  10. using System.Collections.Generic;
  11. using System.Xml;
  12. class UniqueContractNameValidationBehavior : IServiceBehavior
  13. {
  14. Dictionary<XmlQualifiedName, ContractDescription> contracts = new Dictionary<XmlQualifiedName, ContractDescription>();
  15. public UniqueContractNameValidationBehavior() { }
  16. public void Validate(ServiceDescription description, ServiceHostBase serviceHostBase)
  17. {
  18. if (description == null)
  19. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description");
  20. if (serviceHostBase == null)
  21. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceHostBase");
  22. foreach (ServiceEndpoint endpoint in description.Endpoints)
  23. {
  24. XmlQualifiedName qname = new XmlQualifiedName(endpoint.Contract.Name, endpoint.Contract.Namespace);
  25. if (!contracts.ContainsKey(qname))
  26. {
  27. contracts.Add(qname, endpoint.Contract);
  28. }
  29. else if (contracts[qname] != endpoint.Contract)
  30. {
  31. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
  32. SR.GetString(SR.SFxMultipleContractsWithSameName, qname.Name, qname.Namespace)));
  33. }
  34. }
  35. }
  36. public void AddBindingParameters(ServiceDescription description, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection parameters)
  37. {
  38. }
  39. public void ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
  40. {
  41. }
  42. }
  43. }