2 // System.Runtime.Remoting.Channels.Simple.SimpleClientFormatterSink.cs
4 // Author: Dietmar Maurer (dietmar@ximian.com)
6 // 2002 (C) Copyright, Ximian, Inc.
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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
;
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
55 public IMessageSink NextSink
58 return (IMessageSink
) nextInChain
;
62 public IDictionary Properties
69 public IMessageCtrl
AsyncProcessMessage (IMessage msg
,
70 IMessageSink replySink
)
72 throw new NotImplementedException ();
75 public void AsyncProcessRequest (IClientChannelSinkStack sinkStack
,
77 ITransportHeaders headers
,
80 // never called because the formatter sink is
81 // always the first in the chain
82 throw new NotSupportedException ();
86 public void AsyncProcessResponse (IClientResponseChannelSinkStack sinkStack
,
88 ITransportHeaders headers
,
91 throw new NotImplementedException ();
94 public Stream
GetRequestStream (IMessage msg
,
95 ITransportHeaders headers
)
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
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
;
132 nextInChain
.ProcessMessage (msg
, req_headers
, out_stream
, out resp_headers
,
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 ();
143 } catch (Exception e
) {
144 return new ReturnMessage (e
, call
);