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