首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Castle WCF集成设施

Castle WCF集成设施
EN

Stack Overflow用户
提问于 2012-09-15 21:13:18
回答 1查看 2.8K关注 0票数 2

我正在尝试在我的项目中使用Castle WCF集成工具。我遵循了城堡官方网站http://docs.castleproject.org/Windsor.WCF-Facility-Registration.ashx的指示,但我不能让它工作。这是我的代码和配置。

代码语言:javascript
复制
protected void Application_Start(object sender, EventArgs e)
{
    BuildContainer();
}

private void BuildContainer()
    {
        Container = new WindsorContainer();


        //1st
        Container.Kernel.AddFacility<WcfFacility>();
        Container.Kernel.Register(Component.For<IProductService>()
                                           .ImplementedBy<ProductService>()
                                           .Named("ProductService"));

        //2nd
        Container.AddFacility<WcfFacility>()
            .Install(Castle.Windsor.Installer.Configuration.FromXmlFile("Castle.config"));



        //3rd
        Container.Register(
                   Component.For<IProductService>()
                       .ImplementedBy<ProductService>()
                       .LifeStyle.PerWcfOperation()
                       .AsWcfService(new DefaultServiceModel()
                           .AddEndpoints(WcfEndpoint.BoundTo(new WSHttpBinding(SecurityMode.None)
                           {
                               MaxReceivedMessageSize = Int32.MaxValue,
                               MaxBufferPoolSize = Int32.MaxValue,
                               ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas
                               {
                                   MaxStringContentLength = Int32.MaxValue
                               }
                           }).At("http://localhost:1278/ProductService")
                    )
                    .AddBaseAddresses("http://localhost:1278/ProductService")
                    .PublishMetadata()
                       ));
    }

正如你在上面看到的,我试着用3种不同的方式注册我的服务。为了清楚,我一次只运行这3个注册码中的一个,其他的都被注释掉了。从castle.config获取配置的是我的castle.config:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <components>
        <component id="TestService"
                       service="IProductService"
                       type="ProductService"
               lifestyle="transient">
        </component>
    </components>
</configuration>

最后这是我的web.config

代码语言:javascript
复制
<?xml version="1.0"?>

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>

 <system.serviceModel>
  <behaviors>
   <serviceBehaviors>
    <behavior name="">
     <serviceMetadata httpGetEnabled="true" />
     <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
   </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
     <services>
         <service name="WCFLibrary.ProductService">
             <endpoint name ="IProductService_Endpoint" address="http://localhost:1278/ProductService" binding="httpBinding" contract="WCFLibrary.IProductService" />
         </service>
     </services>
 </system.serviceModel>
</configuration>

非常感谢你的帮助...

EN

回答 1

Stack Overflow用户

发布于 2012-09-16 01:22:46

您可以注册您的服务,但不是注册到城堡WcfFacility的DefaultServiceHostFactory中使用的Windsor内核。

IMO最简单的方法是创建一个从DefaultServiceHostFactory派生的自定义服务主机工厂。下面展示了在创建服务实例之前将服务注册到内核的一种优雅方法:http://blog.ploeh.dk/2010/05/18/SneakViewAtCastlesWCFFacility.aspx。当然,您必须修改您的.svc文件以使用您的自定义工厂类,而不是DefaultServiceHostFactory,例如:

代码语言:javascript
复制
<%@ ServiceHost Language="C#" Service="MyService"
Factory="MyProject.MyServiceHostFactory, MyProject"  %>

本质上,您将准备好的容器传递给DefaultServiceHostFactory的构造器,然后该构造器将使用该容器来解析服务及其依赖项。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12437673

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档