我正在尝试使用Castle-Windsor 2.5 (.NET 4)在控制台应用程序中托管一个WCF服务,代码如下:
new WindsorContainer()
.AddFacility<WcfFacility>()
.Register(
Component.For<IMyService>().ImplementedBy<MyService>()
.ActAs(new DefaultServiceModel()
.AddEndpoints(
WcfEndpoint.BoundTo(new BasicHttpBinding()).At("http://localhost:1010/MyService"),
WcfEndpoint.BoundTo(MetadataExchangeBindings.CreateMexHttpBinding()).At("http://localhost:1010/MyService/mex"))
));如果可能的话,我没有也不希望在我的app.config中有任何WCF配置。
然而,这似乎不起作用(没有抱怨,但WcfTestUtil看不到服务)。
我错过了什么吗?
发布于 2010-08-22 17:11:15
我把这个问题贴在了城堡谷歌群组上,并得到了更好的反馈,但由于这比谷歌群组更友好(讽刺!),我将在这里为其他人张贴答案的链接:http://groups.google.com/group/castle-project-users/browse_thread/thread/d670d8f1d7aae0ab
发布于 2013-03-05 07:40:53
基于来自Google Groups的Khash链接,以下是实现此功能的最低限度的代码:
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container
.AddFacility<WcfFacility>()
.Register(
Component.For<ICoreService>()
.ImplementedBy<CoreService>()
.AsWcfService(new DefaultServiceModel()
.AddBaseAddresses("http://localhost:1000/core")
.AddEndpoints(WcfEndpoint.BoundTo(new BasicHttpBinding()))
.PublishMetadata(o => o.EnableHttpGet()))
);
}发布于 2014-09-26 15:14:49
我正在使用wcfFacility 3.3.0并在windows服务中托管wcf服务dll这是我的工作组件注册:(add Hosted() )
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.AddFacility<LoggingFacility>(f => f.UseLog4Net());
container
.AddFacility<WcfFacility>(f =>
{
f.CloseTimeout = TimeSpan.Zero;
});
string baseAddress = "http://localhost:8744/TVIRecorderWcfService/";
container.Register(
Component
.For<ITVIRecorderWcfService>()
.ImplementedBy<TVIRecorderWcfService>()
.AsWcfService(
new DefaultServiceModel()
.AddBaseAddresses(baseAddress)
.Hosted()
//publish metadata doesn't work, have to do differently
//.PublishMetadata(x => x.EnableHttpGet()).Discoverable()
.AddEndpoints(WcfEndpoint
.BoundTo(new BasicHttpBinding()))
//.PublishMetadata(x=>x.EnableHttpGet()).Discoverable()
).LifestyleSingleton()
,
Component
.For<ServiceBase>()
.ImplementedBy<TVIRecorderService>());
}要被WcfTestClient工具看到,服务必须发布它的serviceMetadata我必须在实例化我的ServiceHost之后手动添加serviceBehaviour和MetadataExchangeBindings
var binding = MetadataExchangeBindings.CreateMexHttpBinding();
var mexAddress = "http://localhost:8744/TVIRecorderWcfService/mex";
var behaviour = new ServiceMetadataBehavior() {HttpGetEnabled = true};
serviceHost.Description.Behaviors.Add(behaviour);
serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), binding, mexAddress);https://stackoverflow.com/questions/3370761
复制相似问题