SimpleClientFormatterSink.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // System.Runtime.Remoting.Channels.Simple.SimpleClientFormatterSink.cs
  3. //
  4. // Author: Dietmar Maurer ([email protected])
  5. //
  6. // 2002 (C) Copyright, Ximian, Inc.
  7. //
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System.Collections;
  29. using System.IO;
  30. using System.Runtime.Remoting.Messaging;
  31. using System.Runtime.Remoting.Channels;
  32. namespace System.Runtime.Remoting.Channels.Simple
  33. {
  34. public class SimpleClientFormatterSink : IClientFormatterSink,
  35. IMessageSink, IClientChannelSink, IChannelSinkBase
  36. {
  37. IClientChannelSink nextInChain;
  38. SimpleWireFormat format = new SimpleWireFormat ();
  39. public SimpleClientFormatterSink (IClientChannelSink nextSink)
  40. {
  41. nextInChain = nextSink;
  42. }
  43. public IClientChannelSink NextChannelSink
  44. {
  45. get {
  46. return nextInChain;
  47. }
  48. }
  49. public IMessageSink NextSink
  50. {
  51. get {
  52. return (IMessageSink) nextInChain;
  53. }
  54. }
  55. public IDictionary Properties
  56. {
  57. get {
  58. return null;
  59. }
  60. }
  61. public IMessageCtrl AsyncProcessMessage (IMessage msg,
  62. IMessageSink replySink)
  63. {
  64. throw new NotImplementedException ();
  65. }
  66. public void AsyncProcessRequest (IClientChannelSinkStack sinkStack,
  67. IMessage msg,
  68. ITransportHeaders headers,
  69. Stream stream)
  70. {
  71. // never called because the formatter sink is
  72. // always the first in the chain
  73. throw new NotSupportedException ();
  74. }
  75. [MonoTODO]
  76. public void AsyncProcessResponse (IClientResponseChannelSinkStack sinkStack,
  77. object state,
  78. ITransportHeaders headers,
  79. Stream stream)
  80. {
  81. throw new NotImplementedException ();
  82. }
  83. public Stream GetRequestStream (IMessage msg,
  84. ITransportHeaders headers)
  85. {
  86. // never called
  87. throw new NotSupportedException ();
  88. }
  89. public void ProcessMessage (IMessage msg,
  90. ITransportHeaders requestHeaders,
  91. Stream requestStream,
  92. out ITransportHeaders responseHeaders,
  93. out Stream responseStream)
  94. {
  95. // never called because the formatter sink is
  96. // always the first in the chain
  97. throw new NotSupportedException ();
  98. }
  99. public IMessage SyncProcessMessage (IMessage msg)
  100. {
  101. IMethodCallMessage call = (IMethodCallMessage)msg;
  102. // we catch all exceptions to return them as message
  103. try {
  104. // create a new header
  105. TransportHeaders req_headers = new TransportHeaders ();
  106. req_headers[CommonTransportKeys.RequestUri] = call.Uri;
  107. //fixme: set some header values
  108. Stream out_stream = new MemoryStream ();
  109. // serialize msg to the stream
  110. format.SerializeRequest (out_stream, msg);
  111. // call the next sink
  112. ITransportHeaders resp_headers;
  113. Stream resp_stream;
  114. nextInChain.ProcessMessage (msg, req_headers, out_stream, out resp_headers,
  115. out resp_stream);
  116. // deserialize resp_stream
  117. IMessage result = (IMessage) format.DeserializeResponse (resp_stream, call);
  118. // it's save to close the stream now
  119. resp_stream.Close ();
  120. return result;
  121. } catch (Exception e) {
  122. return new ReturnMessage (e, call);
  123. }
  124. }
  125. }
  126. }