We're currently using Castle on a WPF project with great results and now
I'm trying to get a WCF project up and running using it too but I'm
struggling to find documentation on how to do this properly and the results
I'm getting from my own development are sometimes confusing and
inconsistent.
My service is very trivial (just incrementing a counter so I can test
PerCall against PerSession) at the moment and I register it like this (in
Global.asax)
IWindsorContainer _container;
protected void Application_Start(object sender, EventArgs e)
{
_container = new WindsorContainer();
_container.AddFacility<WcfFacility>(f => f.CloseTimeout =
TimeSpan.Zero)
.Register
(
Component.For<IHeartBeatRepository>()
.ImplementedBy<HeartBeatRepository>().LifestylePerWcfOperation(),
Component.For<IHeartBeatService>()
.ImplementedBy<HeartBeatManager>().LifestyleTransient()
.Named("HeartBeatServices")
.AsWcfService(new
DefaultServiceModel().Hosted())
);
}
protected void Application_End(object sender, EventArgs e)
{
if (_container != null)
_container.Dispose();
}
My test client castle code looks like this:
var container = new WindsorContainer();
container.AddFacility<WcfFacility>().Register
(
Component.For<IHeartBeatService>()
.AsWcfClient(new DefaultClientModel
{
Endpoint =
WcfEndpoint.FromConfiguration("HeartBeatService_wsHttpBinding")
})
.LifestyleTransient()
);
container.Register(Component.For<IForm1>().ImplementedBy<Form1>().LifestyleSingleton());
container.Register(Component.For<IHeartBeatClient>().ImplementedBy<HeartBeatClient>().LifestyleSingleton());
My question is mainly about what Lifestyles I should be using. From what
I've read when using the WCFFacility there's no need to decorate the
Service class with the the InstanceContextMode like this:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class HeartBeatManager : IHeartBeatService
However, if I don't do this then it's always acting as a PerSession no
matter what Lifestyles I set the container to. It seems like I need to set
this on the class to get what I want.
Another question relates to knowing whether the proxy has been closed. If I
wasn't using Castle, I'd open a proxy, perform the operation and then close
it. How do I achieve the same using the WCFFacility - or is the proxy
closed automatically as soon as the call returns. I'm not sure it is as
when I changed it to per session it seemed to only get closed based on the
InactivityTimeout setting in my web.config.
So in summary, what Lifestyle settings should I be using (and do I still
need to decorate my Services) and how does the proxy get closed -
particularly if I'm using it PerSession.
Thanks
Mark
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/d/optout.