SimpleClientFormatterSink.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. using System.Collections;
  9. using System.IO;
  10. using System.Runtime.Remoting.Messaging;
  11. using System.Runtime.Remoting.Channels;
  12. namespace System.Runtime.Remoting.Channels.Simple
  13. {
  14. public class SimpleClientFormatterSink : IClientFormatterSink,
  15. IMessageSink, IClientChannelSink, IChannelSinkBase
  16. {
  17. IClientChannelSink nextInChain;
  18. SimpleWireFormat format = new SimpleWireFormat ();
  19. public SimpleClientFormatterSink (IClientChannelSink nextSink)
  20. {
  21. nextInChain = nextSink;
  22. }
  23. public IClientChannelSink NextChannelSink
  24. {
  25. get {
  26. return nextInChain;
  27. }
  28. }
  29. public IMessageSink NextSink
  30. {
  31. get {
  32. return (IMessageSink) nextInChain;
  33. }
  34. }
  35. public IDictionary Properties
  36. {
  37. get {
  38. return null;
  39. }
  40. }
  41. public IMessageCtrl AsyncProcessMessage (IMessage msg,
  42. IMessageSink replySink)
  43. {
  44. throw new NotImplementedException ();
  45. }
  46. public void AsyncProcessRequest (IClientChannelSinkStack sinkStack,
  47. IMessage msg,
  48. ITransportHeaders headers,
  49. Stream stream)
  50. {
  51. // never called because the formatter sink is
  52. // always the first in the chain
  53. throw new NotSupportedException ();
  54. }
  55. [MonoTODO]
  56. public void AsyncProcessResponse (IClientResponseChannelSinkStack sinkStack,
  57. object state,
  58. ITransportHeaders headers,
  59. Stream stream)
  60. {
  61. throw new NotImplementedException ();
  62. }
  63. public Stream GetRequestStream (IMessage msg,
  64. ITransportHeaders headers)
  65. {
  66. // never called
  67. throw new NotSupportedException ();
  68. }
  69. public void ProcessMessage (IMessage msg,
  70. ITransportHeaders requestHeaders,
  71. Stream requestStream,
  72. out ITransportHeaders responseHeaders,
  73. out Stream responseStream)
  74. {
  75. // never called because the formatter sink is
  76. // always the first in the chain
  77. throw new NotSupportedException ();
  78. }
  79. public IMessage SyncProcessMessage (IMessage msg)
  80. {
  81. IMethodCallMessage call = (IMethodCallMessage)msg;
  82. // we catch all exceptions to return them as message
  83. try {
  84. // create a new header
  85. TransportHeaders req_headers = new TransportHeaders ();
  86. req_headers[CommonTransportKeys.RequestUri] = call.Uri;
  87. //fixme: set some header values
  88. Stream out_stream = new MemoryStream ();
  89. // serialize msg to the stream
  90. format.SerializeRequest (out_stream, msg);
  91. // call the next sink
  92. ITransportHeaders resp_headers;
  93. Stream resp_stream;
  94. nextInChain.ProcessMessage (msg, req_headers, out_stream, out resp_headers,
  95. out resp_stream);
  96. // deserialize resp_stream
  97. IMessage result = (IMessage) format.DeserializeResponse (resp_stream, call);
  98. // it's save to close the stream now
  99. resp_stream.Close ();
  100. return result;
  101. } catch (Exception e) {
  102. return new ReturnMessage (e, call);
  103. }
  104. }
  105. }
  106. }