我正在尝试使用带有以下代码的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无法看到该服务)。
我错过了什么吗?
答案 0 :(得分:3)
在Castle Google网上论坛上发布了这个问题并获得了更好的反馈,但由于这些Google比Google网上论坛更友好(反讽!),我将在此处发布链接到其他人的答案: http://groups.google.com/group/castle-project-users/browse_thread/thread/d670d8f1d7aae0ab
答案 1 :(得分:1)
根据Khash与Google网上论坛的链接,以下是实现此功能的最低限度代码:
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()))
);
}
答案 2 :(得分:1)
我在Windows服务中使用wcfFacility 3.3.0并托管wcf服务dll 这是我的工作组件注册:(添加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 util看到,该服务必须发布它的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);