InputOrReplyRequestProcessor.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. using System.ServiceModel.MonoInternal;
  9. namespace System.ServiceModel.Dispatcher
  10. {
  11. internal class InputOrReplyRequestProcessor : BaseRequestProcessor
  12. {
  13. DispatchRuntime dispatch_runtime;
  14. IChannel reply_or_input;
  15. public InputOrReplyRequestProcessor (DispatchRuntime runtime, IChannel replyOrInput)
  16. {
  17. Init (runtime, replyOrInput);
  18. //initialization
  19. InitializeChain.AddHandler (new InitializingHandler ());
  20. //processing
  21. ProcessingChain.AddHandler (new PostReceiveRequestHandler ()).
  22. AddHandler(new SecurityHandler ()).
  23. AddHandler(new OperationInvokerHandler (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;
  48. if (dispatch_runtime.CallbackClientRuntime.CallbackClientType != null) {
  49. var type = ServiceProxyGenerator.CreateCallbackProxyType (dispatch_runtime.Type, dispatch_runtime.CallbackClientRuntime.CallbackClientType);
  50. contextChannel = (ServiceRuntimeChannel) Activator.CreateInstance (type, new object [] {reply_or_input, dispatch_runtime});
  51. }
  52. else
  53. contextChannel = new ServiceRuntimeChannel (reply_or_input, dispatch_runtime);
  54. OperationContext opCtx = new OperationContext (contextChannel);
  55. opCtx.IncomingMessage = incoming;
  56. opCtx.EndpointDispatcher = dispatch_runtime.EndpointDispatcher;
  57. return opCtx;
  58. }
  59. }
  60. }