【问题标题】:Castle WCF Integration FacilityCastle WCF 集成设施
【发布时间】:2012-09-16 01:22:45
【问题描述】:

我正在尝试在我的项目中使用 Castle WCF 集成工具。我按照城堡官方网站http://docs.castleproject.org/Windsor.WCF-Facility-Registration.ashx的指示进行操作 但我无法让它工作。这是我的代码和配置。

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 :

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <components>
        <component id="TestService"
                       service="IProductService"
                       type="ProductService"
               lifestyle="transient">
        </component>
    </components>
</configuration>

最后是我的 web.config

<?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>

非常感谢您的帮助...

【问题讨论】:

    标签: wcf castle-windsor castle wcffacility


    【解决方案1】:

    您可能正在注册您的服务,但没有注册到 Castle WcfFacility 的 DefaultServiceHostFactory 中使用的 Windsor 内核。

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

    <%@ ServiceHost Language="C#" Service="MyService"
    Factory="MyProject.MyServiceHostFactory, MyProject"  %>
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多