InputOrReplyRequestProcessor.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ServiceModel;
  4. using System.ServiceModel.Channels;
  5. using System.ServiceModel.Security;
  6. using System.ServiceModel.Security.Tokens;
  7. using System.Text;
  8. namespace System.ServiceModel.Dispatcher
  9. {
  10. internal class InputOrReplyRequestProcessor : BaseRequestProcessor
  11. {
  12. DispatchRuntime dispatch_runtime;
  13. IChannel reply_or_input;
  14. IDefaultCommunicationTimeouts communication_timeouts;
  15. public InputOrReplyRequestProcessor (DispatchRuntime runtime, IChannel replyOrInput, IDefaultCommunicationTimeouts timeouts)
  16. {
  17. Init (runtime, reply_or_input, timeouts);
  18. //initialization
  19. InitializeChain.AddHandler (new InitializingHandler ());
  20. //processing
  21. ProcessingChain.AddHandler (new PostReceiveRequestHandler ()).
  22. AddHandler(new SecurityHandler ()).
  23. AddHandler(new OperationInvokerHandler ()).
  24. AddHandler(new ReplyHandler ());
  25. //errors
  26. ErrorChain.AddHandler (new ErrorProcessingHandler ());
  27. //finalize
  28. FinalizationChain.AddHandler (new FinalizeProcessingHandler ());
  29. }
  30. void Init (DispatchRuntime runtime, IChannel replyOrInput, IDefaultCommunicationTimeouts timeouts)
  31. {
  32. dispatch_runtime = runtime;
  33. reply_or_input = replyOrInput;
  34. communication_timeouts = timeouts;
  35. }
  36. public void ProcessInput (Message message)
  37. {
  38. OperationContext opcx = CreateOperationContext (message);
  39. ProcessRequest (new MessageProcessingContext (opcx));
  40. }
  41. public void ProcessReply (RequestContext rc)
  42. {
  43. OperationContext opcx = CreateOperationContext (rc.RequestMessage);
  44. opcx.RequestContext = rc;
  45. ProcessRequest (new MessageProcessingContext (opcx));
  46. }
  47. OperationContext CreateOperationContext (Message incoming)
  48. {
  49. ServiceRuntimeChannel contextChannel = new ServiceRuntimeChannel (reply_or_input,
  50. dispatch_runtime.ChannelDispatcher.DefaultOpenTimeout,
  51. dispatch_runtime.ChannelDispatcher.DefaultCloseTimeout);
  52. OperationContext opCtx = new OperationContext (contextChannel);
  53. opCtx.IncomingMessage = incoming;
  54. opCtx.EndpointDispatcher = dispatch_runtime.EndpointDispatcher;
  55. opCtx.CommunicationTimeouts = communication_timeouts;
  56. return opCtx;
  57. }
  58. }
  59. }