PeerValidationBehavior.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. [ObsoleteAttribute ("PeerChannel feature is obsolete and will be removed in the future.", false)]
  12. class PeerValidationBehavior : IEndpointBehavior, IServiceBehavior
  13. {
  14. public static PeerValidationBehavior Instance
  15. {
  16. get
  17. {
  18. if (instance == null)
  19. instance = new PeerValidationBehavior();
  20. return instance;
  21. }
  22. }
  23. static PeerValidationBehavior instance;
  24. PeerValidationBehavior() { }
  25. static bool IsRequestReplyContract(ContractDescription contract)
  26. {
  27. bool requestReply = false;
  28. foreach (OperationDescription operation in contract.Operations)
  29. {
  30. if (operation.Messages.Count > 1) // Request-reply
  31. {
  32. requestReply = true;
  33. break;
  34. }
  35. }
  36. return requestReply;
  37. }
  38. void IEndpointBehavior.Validate(ServiceEndpoint serviceEndpoint)
  39. {
  40. if (serviceEndpoint == null)
  41. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceEndpoint");
  42. ContractDescription contract = serviceEndpoint.Contract;
  43. Binding binding = serviceEndpoint.Binding;
  44. ValidateHelper(contract, binding);
  45. }
  46. void IEndpointBehavior.AddBindingParameters(ServiceEndpoint serviceEndpoint, BindingParameterCollection bindingParameters)
  47. {
  48. }
  49. void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher)
  50. {
  51. }
  52. void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime behavior)
  53. {
  54. }
  55. void IServiceBehavior.AddBindingParameters(ServiceDescription description, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection parameters)
  56. {
  57. }
  58. void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
  59. {
  60. }
  61. void IServiceBehavior.Validate(ServiceDescription description, ServiceHostBase serviceHostBase)
  62. {
  63. if (description == null)
  64. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description");
  65. for (int i = 0; i < description.Endpoints.Count; i++)
  66. {
  67. ServiceEndpoint endpoint = description.Endpoints[i];
  68. ValidateHelper(endpoint.Contract, endpoint.Binding);
  69. }
  70. }
  71. // SM doesn't support request-reply message pattern over multi-point channels correctly, so, disabling
  72. // request-reply for NetPeerTcpBinding. (Advanced users may find a way to implement request-reply over
  73. // a CustomBinding that includes PeerTransportBE.)
  74. void ValidateHelper(ContractDescription contract, Binding binding)
  75. {
  76. if (binding is NetPeerTcpBinding && IsRequestReplyContract(contract))
  77. {
  78. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
  79. SR.GetString(SR.BindingDoesnTSupportRequestReplyButContract1, binding.Name)));
  80. }
  81. }
  82. }
  83. }