Exception while hosting a WCF Service in a DependencyInjection Module ?
- by Maciek
Hello,
I've written a small just-for-fun console project using Ninject, I'm pasting some of the code below just so that you get the idea :
Program.cs
using System;
using Ninject;
using Ninjectionn.Modules; // My namespace for my modules
namespace Ninjections
{
class Program
{
static void Main(string[] args)
{
IKernel kernel = new StandardKernel();
kernel.Load<ServicesHostModule>();
Console.ReadKey();
}
}
}
ServicesHostModule.cs
using System;
using System.ServiceModel;
using Ninject;
using Ninject.Modules;
namespace Ninjections.Modules
{
public class ServicesHostModule : INinjectModule
{
#region INinjectModule Members
public string Name { get { return "ServicesHost"; }}
public void OnLoad(IKernel kernel)
{
if(m_host != null)
m_host.Close();
else
m_host = new ServiceHost(typeof(WCFTestService));
m_host.Open(); // (!) EXCEPTION HERE
}
public void OnUnLoad(IKernel kernel)
{
m_host.Close();
}
#endregion
}
}
ITestWCFService.cs
using System.ServiceModel;
namespace Ninjections.Modules
{
[ServiceContract]
public interface ITestWCFService
{
[OperationContract]
string GetString1();
[OperationContract]
string GetString2();
}
}
An auto-generated App.config is in the ServicesHostModule project. I've "added" an existing item (the app config) as link in the main project.
Q: at the m_host.Open(); line, an InvalidOperationException occurs. The message says : "Service "Ninjections.Modules.TestWCFService" has zero application endopints. What's wrong?