1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Facilities
.WcfIntegration
18 using System
.Reflection
;
19 using System
.ServiceModel
;
21 public class WcfClientModel
: WcfEndpoint
23 public WcfClientModel()
27 public WcfClientModel(Type contract
)
32 public WcfClientModel(string endpointName
)
34 EndpointName
= endpointName
;
37 public WcfClientModel(Type contract
, string endpointName
)
40 EndpointName
= endpointName
;
44 internal CreateChannel
GetChannelBuilder()
46 return GetChannelBuilder(Contract
);
49 internal CreateChannel
GetChannelBuilder(Type contract
)
52 contract
= contract
?? Contract
;
53 Type type
= typeof(ChannelFactory
<>).MakeGenericType(new Type
[] { contract }
);
55 if (!string.IsNullOrEmpty(EndpointName
))
57 target
= Activator
.CreateInstance(type
, new object[] { EndpointName }
);
61 EndpointAddress address
= EndpointAddress
;
64 address
= new EndpointAddress(Address
);
66 target
= Activator
.CreateInstance(type
, new object[] { Binding, address }
);
69 MethodInfo methodInfo
= type
.GetMethod("CreateChannel", new Type
[0]);
70 return (CreateChannel
) Delegate
.CreateDelegate(typeof(CreateChannel
), target
, methodInfo
);
74 public class WcfClientModel
<Contract
> : WcfClientModel
76 public WcfClientModel()
77 : base(typeof(Contract
))
81 public WcfClientModel(string endpointName
) : this()
83 EndpointName
= endpointName
;