Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Facilities / Wcf / Castle.Facilities.WcfIntegration / Client / AbstractChannelBuilder.cs
blob2ccca1788278088c35c67c5493da0897d16840e1
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
18 using System.ServiceModel;
19 using System.ServiceModel.Description;
20 using System.ServiceModel.Channels;
21 using Castle.MicroKernel;
23 public abstract class AbstractChannelBuilder : IWcfEndpointVisitor
25 private Type contract;
26 private readonly IKernel kernel;
27 private ChannelCreator channelCreator;
29 public AbstractChannelBuilder(IKernel kernel)
31 this.kernel = kernel;
34 protected IKernel Kernel
36 get { return kernel; }
39 protected ChannelCreator GetEndpointChannelCreator(IWcfEndpoint endpoint)
41 return GetEndpointChannelCreator(endpoint, null);
44 protected ChannelCreator GetEndpointChannelCreator(IWcfEndpoint endpoint, Type contract)
46 this.contract = contract ?? endpoint.Contract;
47 endpoint.Accept(this);
48 return channelCreator;
51 protected abstract ChannelCreator GetChannel(Type contract);
52 protected abstract ChannelCreator GetChannel(Type contract, ServiceEndpoint endpoint);
53 protected abstract ChannelCreator GetChannel(Type contract, string configurationName);
54 protected abstract ChannelCreator GetChannel(Type contract, Binding binding, string address);
55 protected abstract ChannelCreator GetChannel(Type contract, Binding binding, EndpointAddress address);
57 #region IWcfEndpointVisitor Members
59 void IWcfEndpointVisitor.VisitContractEndpoint(ContractEndpointModel model)
61 channelCreator = GetChannel(contract);
64 void IWcfEndpointVisitor.VisitServiceEndpoint(ServiceEndpointModel model)
66 channelCreator = GetChannel(contract, model.ServiceEndpoint);
69 void IWcfEndpointVisitor.VisitConfigurationEndpoint(ConfigurationEndpointModel model)
71 channelCreator = GetChannel(contract, model.EndpointName);
74 void IWcfEndpointVisitor.VisitBindingEndpoint(BindingEndpointModel model)
76 channelCreator = GetChannel(contract, model.Binding, string.Empty);
79 void IWcfEndpointVisitor.VisitBindingAddressEndpoint(BindingAddressEndpointModel model)
81 if (model.HasViaAddress)
83 EndpointAddress address = model.EndpointAddress ?? new EndpointAddress(model.Address);
84 ContractDescription description = ContractDescription.GetContract(contract);
85 ServiceEndpoint endpoint = new ServiceEndpoint(description, model.Binding, address);
86 endpoint.Behaviors.Add(new ClientViaBehavior(model.ViaAddress));
87 channelCreator = GetChannel(contract, endpoint);
89 else
91 if (model.EndpointAddress != null)
93 channelCreator = GetChannel(contract, model.Binding, model.EndpointAddress);
95 else
97 channelCreator = GetChannel(contract, model.Binding, model.Address);
102 #endregion