ContextReplySessionChannel.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Channels
  5. {
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ServiceModel;
  9. class ContextReplySessionChannel : LayeredChannel<IReplySessionChannel>, IReplySessionChannel
  10. {
  11. ContextProtocol contextProtocol;
  12. public ContextReplySessionChannel(ChannelManagerBase channelManager, IReplySessionChannel innerChannel, ContextExchangeMechanism contextExchangeMechanism)
  13. : base(channelManager, innerChannel)
  14. {
  15. this.contextProtocol = new ServiceContextProtocol(contextExchangeMechanism);
  16. }
  17. public EndpointAddress LocalAddress
  18. {
  19. get { return this.InnerChannel.LocalAddress; }
  20. }
  21. public IInputSession Session
  22. {
  23. get { return this.InnerChannel.Session; }
  24. }
  25. public IAsyncResult BeginReceiveRequest(TimeSpan timeout, AsyncCallback callback, object state)
  26. {
  27. return this.InnerChannel.BeginReceiveRequest(timeout, callback, state);
  28. }
  29. public IAsyncResult BeginReceiveRequest(AsyncCallback callback, object state)
  30. {
  31. return this.InnerChannel.BeginReceiveRequest(callback, state);
  32. }
  33. public IAsyncResult BeginTryReceiveRequest(TimeSpan timeout, AsyncCallback callback, object state)
  34. {
  35. return this.InnerChannel.BeginTryReceiveRequest(timeout, callback, state);
  36. }
  37. public IAsyncResult BeginWaitForRequest(TimeSpan timeout, AsyncCallback callback, object state)
  38. {
  39. return this.InnerChannel.BeginWaitForRequest(timeout, callback, state);
  40. }
  41. public RequestContext EndReceiveRequest(IAsyncResult result)
  42. {
  43. RequestContext innerContext = this.InnerChannel.EndReceiveRequest(result);
  44. if (innerContext == null)
  45. {
  46. return null;
  47. }
  48. else
  49. {
  50. return this.CreateContextChannelRequestContext(innerContext);
  51. }
  52. }
  53. public bool EndTryReceiveRequest(IAsyncResult result, out RequestContext context)
  54. {
  55. context = null;
  56. RequestContext innerContext;
  57. if (this.InnerChannel.EndTryReceiveRequest(result, out innerContext))
  58. {
  59. if (innerContext != null)
  60. {
  61. context = this.CreateContextChannelRequestContext(innerContext);
  62. }
  63. return true;
  64. }
  65. else
  66. {
  67. return false;
  68. }
  69. }
  70. public bool EndWaitForRequest(IAsyncResult result)
  71. {
  72. return this.InnerChannel.EndWaitForRequest(result);
  73. }
  74. public RequestContext ReceiveRequest(TimeSpan timeout)
  75. {
  76. RequestContext innerContext = this.InnerChannel.ReceiveRequest(timeout);
  77. if (innerContext == null)
  78. {
  79. return null;
  80. }
  81. else
  82. {
  83. return this.CreateContextChannelRequestContext(innerContext);
  84. }
  85. }
  86. public RequestContext ReceiveRequest()
  87. {
  88. RequestContext innerContext = this.InnerChannel.ReceiveRequest();
  89. if (innerContext == null)
  90. {
  91. return null;
  92. }
  93. else
  94. {
  95. return this.CreateContextChannelRequestContext(innerContext);
  96. }
  97. }
  98. public bool TryReceiveRequest(TimeSpan timeout, out RequestContext context)
  99. {
  100. RequestContext innerContext;
  101. if (this.InnerChannel.TryReceiveRequest(timeout, out innerContext))
  102. {
  103. context = this.CreateContextChannelRequestContext(innerContext);
  104. return true;
  105. }
  106. else
  107. {
  108. context = null;
  109. return false;
  110. }
  111. }
  112. public bool WaitForRequest(TimeSpan timeout)
  113. {
  114. return this.InnerChannel.WaitForRequest(timeout);
  115. }
  116. ContextChannelRequestContext CreateContextChannelRequestContext(RequestContext innerContext)
  117. {
  118. this.contextProtocol.OnIncomingMessage(innerContext.RequestMessage);
  119. return new ContextChannelRequestContext(innerContext, this.contextProtocol, this.DefaultSendTimeout);
  120. }
  121. }
  122. }