5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2005 Novell, Inc. http://www.novell.com
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
29 using System
.Collections
.Generic
;
30 using System
.Collections
.ObjectModel
;
31 using System
.Reflection
;
32 using System
.ServiceModel
;
33 using System
.ServiceModel
.Channels
;
34 using System
.ServiceModel
.Description
;
37 namespace System
.ServiceModel
.Dispatcher
40 public sealed class ClientOperation
42 internal class ClientOperationCollection
:
44 KeyedCollection
<string, ClientOperation
>
46 SynchronizedKeyedCollection
<string, ClientOperation
>
49 protected override string GetKeyForItem (ClientOperation o
)
56 string name
, action
, reply_action
;
57 MethodInfo sync_method
, begin_method
, end_method
;
58 bool deserialize_reply
= true, serialize_request
= true;
59 bool is_initiating
, is_terminating
, is_oneway
;
60 IClientMessageFormatter formatter
, actual_formatter
;
61 SynchronizedCollection
<IParameterInspector
> inspectors
62 = new SynchronizedCollection
<IParameterInspector
> ();
64 SynchronizedCollection
<FaultContractInfo
> fault_contract_infos
= new SynchronizedCollection
<FaultContractInfo
> ();
67 public ClientOperation (ClientRuntime parent
,
68 string name
, string action
)
75 public ClientOperation (ClientRuntime parent
,
76 string name
, string action
, string replyAction
)
81 this.reply_action
= replyAction
;
84 public string Action
{
85 get { return action; }
88 public string ReplyAction
{
89 get { return reply_action; }
92 public MethodInfo BeginMethod
{
93 get { return begin_method; }
94 set { begin_method = value; }
97 public bool DeserializeReply
{
98 get { return deserialize_reply; }
99 set { deserialize_reply = value; }
102 public MethodInfo EndMethod
{
103 get { return end_method; }
104 set { end_method = value; }
108 public SynchronizedCollection
<FaultContractInfo
> FaultContractInfos
{
109 get { return fault_contract_infos; }
113 public IClientMessageFormatter Formatter
{
114 get { return formatter; }
115 set { formatter = value; }
118 public bool IsInitiating
{
119 get { return is_initiating; }
120 set { is_initiating = value; }
123 public bool IsOneWay
{
124 get { return is_oneway; }
125 set { is_oneway = value; }
128 public bool IsTerminating
{
129 get { return is_terminating; }
130 set { is_terminating = value; }
137 public SynchronizedCollection
<IParameterInspector
> ParameterInspectors
{
138 get { return inspectors; }
141 public ClientRuntime Parent
{
142 get { return parent; }
145 public bool SerializeRequest
{
146 get { return serialize_request; }
147 set { serialize_request = value; }
150 public MethodInfo SyncMethod
{
151 get { return sync_method; }
152 set { sync_method = value; }
155 OperationDescription Description
{
157 // FIXME: ContractDescription should be acquired from elsewhere.
158 ContractDescription cd
= ContractDescription
.GetContract (Parent
.ContractClientType
);
159 OperationDescription od
= cd
.Operations
.Find (Name
);
162 throw new Exception (String
.Format ("INTERNAL ERROR: Contract {0} in namespace {1} does not contain Operations.", Parent
.ContractName
, Parent
.ContractNamespace
));
164 throw new Exception (String
.Format ("INTERNAL ERROR: Operation {0} was not found.", Name
));
170 internal IClientMessageFormatter
GetFormatter ()
172 if (actual_formatter
== null) {
173 if (Formatter
!= null)
174 actual_formatter
= Formatter
;
176 actual_formatter
= new OperationFormatter (Description
, false, false); // FIXME: pass correct isRpc, isEncoded
178 return actual_formatter
;