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 OperationInvokerHandler (replyOrInput));
  23. //errors
  24. ErrorChain.AddHandler (new ErrorProcessingHandler (replyOrInput));
  25. //finalize
  26. FinalizationChain.AddHandler (new FinalizeProcessingHandler ());
  27. }
  28. void Init (DispatchRuntime runtime, IChannel replyOrInput)
  29. {
  30. dispatch_runtime = runtime;
  31. reply_or_input = replyOrInput;
  32. }
  33. public void ProcessInput (Message message)
  34. {
  35. OperationContext opcx = CreateOperationContext (message);
  36. ProcessRequest (new MessageProcessingContext (opcx));
  37. }
  38. public void ProcessReply (RequestContext rc)
  39. {
  40. OperationContext opcx = CreateOperationContext (rc.RequestMessage);
  41. opcx.RequestContext = rc;
  42. ProcessRequest (new MessageProcessingContext (opcx));
  43. }
  44. OperationContext CreateOperationContext (Message incoming)
  45. {
  46. ServiceRuntimeChannel contextChannel;
  47. if (dispatch_runtime.CallbackClientRuntime.CallbackClientType != null) {
  48. var type = ServiceProxyGenerator.CreateCallbackProxyType (dispatch_runtime, dispatch_runtime.CallbackClientRuntime.CallbackClientType);
  49. contextChannel = (ServiceRuntimeChannel) Activator.CreateInstance (type, new object [] {reply_or_input, dispatch_runtime});
  50. }
  51. else
  52. contextChannel = new ServiceRuntimeChannel (reply_or_input, dispatch_runtime);
  53. contextChannel.Open (); // FIXME: timeout?
  54. OperationContext opCtx = new OperationContext (contextChannel);
  55. opCtx.IncomingMessage = incoming;
  56. opCtx.EndpointDispatcher = dispatch_runtime.EndpointDispatcher;
  57. return opCtx;
  58. }
  59. }
  60. }