Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Castle WCF集成设施_Wcf_Castle Windsor_Castle_Wcffacility - Fatal编程技术网

Castle WCF集成设施

Castle WCF集成设施,wcf,castle-windsor,castle,wcffacility,Wcf,Castle Windsor,Castle,Wcffacility,我试图在我的项目中使用Castle WCF集成工具。我听从城堡官方网站的指示 但我不能让它工作。这是我的代码和配置 protected void Application_Start(object sender, EventArgs e) { BuildContainer(); } private void BuildContainer() { Container = new WindsorContainer(); //1st

我试图在我的项目中使用Castle WCF集成工具。我听从城堡官方网站的指示 但我不能让它工作。这是我的代码和配置

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()
                       ));
    }
受保护的无效应用程序\u启动(对象发送方,事件参数e)
{
BuildContainer();
}
私有void BuildContainer()
{
容器=新WindsorContainer();
//第一
Container.Kernel.AddFacility();
Container.Kernel.Register(Component.For())
.由()实施
。名为(“产品服务”);
//第二
Container.AddFacility()
.Install(Castle.Windsor.Installer.Configuration.FromXmlFile(“Castle.config”);
//第三
集装箱。登记(
用于()的组件
.由()实施
.生活方式
.AsWcfService(新的DefaultServiceModel()
.AddEndpoints(WcfEndpoint.BoundTo)(新的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个注册码中的一个,其他的都被注释掉了。对于从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>


非常感谢您的帮助……

您可能正在注册您的服务,但不是从Castle WCF网站注册到DefaultServiceHostFactory中使用的Windsor内核

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

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

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