Added the ability to change the invocation target in the DefaultProxyFactory.
[castle.git] / Facilities / Wcf / Castle.Facilities.WcfIntegration / Internal / ServiceHostBuilder.cs
blobcba118f46650552831f843c0370a92ca29390b07
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.Internal
17 using System;
18 using System.ServiceModel;
19 using System.ServiceModel.Description;
21 internal class ServiceHostBuilder : IWcfEndpointVisitor
23 private ServiceHost serviceHost;
24 private ServiceEndpoint serviceEndpoint;
26 public ServiceEndpoint AddServiceEndpoint(ServiceHost serviceHost,
27 IWcfEndpoint endpoint)
29 if (serviceHost == null)
31 throw new ArgumentNullException("serviceHost");
34 if (endpoint == null)
36 throw new ArgumentNullException("endpoint");
39 this.serviceHost = serviceHost;
40 endpoint.Accept(this);
41 return serviceEndpoint;
44 #region IWcfEndpointVisitor Members
46 void IWcfEndpointVisitor.VisitServiceEndpointModel(ServiceEndpointModel model)
48 serviceHost.Description.Endpoints.Add(model.ServiceEndpoint);
49 serviceEndpoint = model.ServiceEndpoint;
52 void IWcfEndpointVisitor.VisitConfigurationEndpointModel(ConfigurationEndpointModel model)
54 throw new InvalidOperationException("The ServiceEndpoint for a ServiceHost " +
55 "cannot be created from an endpoint name.");
58 void IWcfEndpointVisitor.VisitBindingEndpointModel(BindingEndpointModel model)
60 serviceEndpoint = serviceHost.AddServiceEndpoint(
61 model.Contract, model.Binding, string.Empty);
64 void IWcfEndpointVisitor.VisitBindingAddressEndpointModel(BindingAddressEndpointModel model)
66 if (model.HasViaAddress)
68 serviceEndpoint = serviceHost.AddServiceEndpoint(
69 model.Contract, model.Binding, model.Address, model.ViaAddress);
71 else
73 serviceEndpoint = serviceHost.AddServiceEndpoint(
74 model.Contract, model.Binding, model.Address);
78 #endregion