InputOrReplyRequestProcessor.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. public InputOrReplyRequestProcessor (DispatchRuntime runtime, IChannel replyOrInput)
  15. {
  16. Init (runtime, reply_or_input);
  17. //initialization
  18. InitializeChain.AddHandler (new InitializingHandler ());
  19. //processing
  20. ProcessingChain.AddHandler (new PostReceiveRequestHandler ()).
  21. AddHandler(new SecurityHandler ()).
  22. AddHandler(new OperationInvokerHandler ()).
  23. AddHandler(new ReplyHandler (replyOrInput));
  24. //errors
  25. ErrorChain.AddHandler (new ErrorProcessingHandler (replyOrInput));
  26. //finalize
  27. FinalizationChain.AddHandler (new FinalizeProcessingHandler ());
  28. }
  29. void Init (DispatchRuntime runtime, IChannel replyOrInput)
  30. {
  31. dispatch_runtime = runtime;
  32. reply_or_input = replyOrInput;
  33. }
  34. public void ProcessInput (Message message)
  35. {
  36. OperationContext opcx = CreateOperationContext (message);
  37. ProcessRequest (new MessageProcessingContext (opcx));
  38. }
  39. public void ProcessReply (RequestContext rc)
  40. {
  41. OperationContext opcx = CreateOperationContext (rc.RequestMessage);
  42. opcx.RequestContext = rc;
  43. ProcessRequest (new MessageProcessingContext (opcx));
  44. }
  45. OperationContext CreateOperationContext (Message incoming)
  46. {
  47. ServiceRuntimeChannel contextChannel = new ServiceRuntimeChannel (reply_or_input,
  48. dispatch_runtime.ChannelDispatcher.DefaultOpenTimeout,
  49. dispatch_runtime.ChannelDispatcher.DefaultCloseTimeout);
  50. OperationContext opCtx = new OperationContext (contextChannel);
  51. opCtx.IncomingMessage = incoming;
  52. opCtx.EndpointDispatcher = dispatch_runtime.EndpointDispatcher;
  53. return opCtx;
  54. }
  55. }
  56. }