使用Spring.Net,如何在控制台应用程序中托管WCF服务?

时间:2011-11-04 14:50:20

标签: c# wcf spring.net

我有一个界面:

[ServiceBehavior]
public interface ICartService
{
string DaoString {get;set;}
public GetString();
}

和一个班级:

public class BigCartService:ICartService
{
public string DaoString {get;set;}
CallPrivateMethod(DaoString);
}

使用Spring.Net,我将对象设置为:

<object id="bigcart" singleton="false" type="Cart.BigCartService, Cart">
  <property name="DaoString" value="1"/>
</object>

如何在Windows控制台应用程序中托管它?

1 个答案:

答案 0 :(得分:3)

检查WCF快速启动(项目'Spring.WcfQuickStart.ServerApp')

你必须这样做:

1)使用Spring的IoC容器

<object id="bigCartHost" type="Spring.ServiceModel.Activation.ServiceHostFactoryObject, Spring.Services">
  <property name="TargetName" value="bigCart" />
</object>

ContextRegistry.GetContext(); // Force Spring to load configuration
Console.Out.WriteLine("Server listening...");
Console.Out.WriteLine("--- Press <return> to quit ---");
Console.ReadLine();

2)以编程方式

using (SpringServiceHost serviceHost = new SpringServiceHost("calculator"))
{
    serviceHost.Open();

    Console.Out.WriteLine("Server listening...");
    Console.Out.WriteLine("--- Press <return> to quit ---");
    Console.ReadLine();
}