2 // ContractDescription.cs
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
;
30 using System
.Collections
.Generic
;
31 using System
.Collections
.ObjectModel
;
32 using System
.Net
.Security
;
33 using System
.Reflection
;
34 using System
.Runtime
.Serialization
;
35 using System
.ServiceModel
;
36 using System
.ServiceModel
.Channels
;
37 using System
.ServiceModel
.Dispatcher
;
39 namespace System
.ServiceModel
.Description
41 public class ContractDescription
44 public static ContractDescription
GetContract (
47 return ContractDescriptionGenerator
.GetContract (contractType
);
51 public static ContractDescription
GetContract (
52 Type contractType
, object serviceImplementation
)
54 return ContractDescriptionGenerator
.GetContract (contractType
, serviceImplementation
);
58 public static ContractDescription
GetContract (
59 Type contractType
, Type serviceType
)
61 return ContractDescriptionGenerator
.GetContract (contractType
, serviceType
);
64 OperationDescriptionCollection operations
;
65 KeyedByTypeCollection
<IContractBehavior
> behaviors
;
66 Type callback_contract_type
, contract_type
;
67 string name
, ns
, config_name
;
68 ProtectionLevel protection_level
;
69 bool has_protection_level
;
72 public ContractDescription (string name
)
77 public ContractDescription (string name
, string ns
)
80 throw new ArgumentNullException ("name");
82 throw new ArgumentOutOfRangeException ("ContractDescription's Name must be a non-empty string.");
84 ns
= "http://tempuri.org/";
88 behaviors
= new KeyedByTypeCollection
<IContractBehavior
> ();
89 operations
= new OperationDescriptionCollection ();
92 public KeyedByTypeCollection
<IContractBehavior
> Behaviors
{
93 get { return behaviors; }
96 public Type CallbackContractType
{
97 get { return callback_contract_type; }
98 set { callback_contract_type = value; }
101 public string ConfigurationName
{
102 get { return config_name; }
103 set { config_name = value; }
106 public Type ContractType
{
107 get { return contract_type; }
108 set { contract_type = value; }
111 public bool HasProtectionLevel
{
112 get { return has_protection_level; }
115 public ProtectionLevel ProtectionLevel
{
116 get { return protection_level; }
118 protection_level
= value;
119 has_protection_level
= true;
125 set { name = value; }
128 public string Namespace
{
133 public OperationDescriptionCollection Operations
{
134 get { return operations; }
137 public SessionMode SessionMode
{
138 get { return session; }
139 set { session = value; }
143 public Collection
<ContractDescription
> GetInheritedContracts ()
145 throw new NotImplementedException ();
148 internal ClientRuntime
CreateClientRuntime ()
150 ClientRuntime proxy
= new ClientRuntime (Name
, Namespace
) { ContractClientType = ContractType, CallbackClientType = CallbackContractType }
;
151 //proxy.ContractClientType = typeof (TChannel);
153 foreach (OperationDescription od
in Operations
) {
154 if (!proxy
.Operations
.Contains (od
.Name
))
155 PopulateClientOperation (proxy
, od
);
157 foreach (IOperationBehavior ob
in od
.Behaviors
)
158 ob
.ApplyClientBehavior (od
, proxy
.Operations
[od
.Name
]);
165 void PopulateClientOperation (ClientRuntime proxy
, OperationDescription od
)
167 string reqA
= null, resA
= null;
168 foreach (MessageDescription m
in od
.Messages
) {
169 if (m
.Direction
== MessageDirection
.Input
)
176 new ClientOperation (proxy
, od
.Name
, reqA
) :
177 new ClientOperation (proxy
, od
.Name
, reqA
, resA
);
178 foreach (MessageDescription md
in od
.Messages
) {
179 if (md
.Direction
== MessageDirection
.Input
&&
180 md
.Body
.Parts
.Count
== 1 &&
181 md
.Body
.Parts
[0].Type
== typeof (Message
))
182 o
.SerializeRequest
= false;
183 if (md
.Direction
== MessageDirection
.Output
&&
184 md
.Body
.ReturnValue
!= null &&
185 md
.Body
.ReturnValue
.Type
== typeof (Message
))
186 o
.DeserializeReply
= false;
188 proxy
.Operations
.Add (o
);