简体   繁体   English

城堡WCF设施容器配置

[英]Castle WCF facility Container Configuration

I'm having real trouble with the WCF Facility provided by Castle Windsor. 我在使用Castle Windsor提供的WCF设施时遇到了麻烦。 I'm not finding appropriate documentation which could point me to some examples with the current version of WCF Facility. 我没有找到适当的文档,可以指出我当前版本的WCF Facility的一些例子。

Following is my scenario: I want to write a WCF service, exposed over TCP which will be hosted by a Windows Service. 以下是我的方案:我想编写一个WCF服务,通过TCP公开,由Windows服务托管。

I'm falling short of how to configure the WCF facility, where to configure it whether it should be in the WCF service or in the windows service host. 我不知道如何配置WCF工具,在哪里配置它是应该在WCF服务中还是在Windows服务主机中。

Also how would I configure the WCF facility when my service end points are declared in the WCF config file? 当我在WCF配置文件中声明我的服务端点时,如何配置WCF工具?

Can someone please help? 有人可以帮忙吗? A link would be much appreciated, although I could not find much. 一个链接将非常感激,虽然我找不到多少。

This is an example/walk-through of setting up a (contrived) service. 这是设置(设计)服务的示例/演练。

For my example, there is a service contract WindsorWCF.IMyService and a service called WindsorWCF.MyService. 对于我的示例,有一个服务契约WindsorWCF.IMyService和一个名为WindsorWCF.MyService的服务。 I've chosen to configure the service with a TCP endpoint in the app config as follows: 我已选择在app config中使用TCP端点配置服务,如下所示:

<system.serviceModel>
  <services>
    <service name="WindsorWCF.MyService">
      <endpoint name ="IMyService_Endpoint" address="net.tcp://localhost:9876/MyService" binding="netTcpBinding" contract="WindsorWCF.IMyService" />
    </service>
  </services>
</system.serviceModel>

Next, add an Window config (XML) file to your service project, and add a component to it: 接下来,将Window配置(XML)文件添加到服务项目,并向其添加组件:

<configuration>
  <components>
    <component id="MyService" service="WindsorWCF.IMyService, WindsorWCF" type="WindsorWCF.MyService, WindsorWCF" />
  </components>
</configuration>

In the service host application itself, I've added the following code (I used a console application when I wrote the code, but the idea is the same): 在服务主机应用程序本身,我添加了以下代码(我在编写代码时使用了控制台应用程序,但想法是一样的):

static void Main(string[] args)
{
    InitWindsor();
    var host = new DefaultServiceHostFactory().CreateServiceHost("MyService", new Uri[0]);
    host.Open();
    Console.ReadLine();
}

static IWindsorContainer Container { get; set; }
private static void InitWindsor ()
{
    Container = new WindsorContainer().AddFacility<WcfFacility>().Install(Configuration.FromXmlFile("windsor.config"));
}

That's it for the example - I trust it makes sense. 就是这个例子 - 我相信它是有道理的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM