InfoLearner
InfoLearner

Reputation: 15598

Using Spring.Net, How to host WCF service in console application?

I have an interface:

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

and a class:

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

Using Spring.Net, I have set the object as:

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

How do I host it in Windows Console Application?

Upvotes: 2

Views: 948

Answers (1)

bbaia
bbaia

Reputation: 1183

Check the WCF quick start (The project 'Spring.WcfQuickStart.ServerApp')

You have to way to do that :

1) Using Spring's IoC container

<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) Programmatically

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

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

Upvotes: 3

Related Questions