I'm playing around with Castle WCF integration facility because I want to integrate my WCF services with windsor IOC.
The issue I'm facing is that I can't set IKernel for DefaultServiceHostFactory.
I setup the container:
container = new WindsorContainer().AddFacility<WcfFacility>();
container.Register(Component.For<DefaultServiceHostFactory>());
container.Register(Component.For<IFoo>().ImplementedBy<Foo>());
Then I setup the SVC file:
<%# ServiceHost
Language="C#"
Debug="true"
Service="Foo"
Factory="Castle.Facilities.WcfIntegration.DefaultServiceHostFactory, Castle.Facilities.WcfIntegration"%>
When WCF tries to instantiate DefaultServiceHostFactory it says kernell is null and recommends using DefaultServiceHostFactory.RegisterContainer(IKernel kernel) method. However this method is not available in latest version of WCF facility.
Any help appriceated!
Thanks
figured it out, I was deploying the application to windows Azure and I used the web role startup for container registration (WRONG!) once I putted the container setup into Global.asax file it started working for IIS and Azure emulator as well.
Related
I am investigating a web project and I have encountered a class library. Its name is "UnitName.SampleProject.WcfIISHost" and it only has two files, one is "CategoryService.svc" and "NinjectFileLessServiceHostFactory.cs". And weirdly, "CategoryService.svc" has only one row, as such:
<%# ServiceHost Language="C#" Debug="true" Service="UnitName.SampleProject.BusinessLayer.Concrete.ProductManagement.CategoryService" Factory="Ninject.Extensions.Wcf.NinjectServiceHostFactory" %>
and content of "NinjectFileLessServiceHostFactory.cs". is:
public class NinjectFileLessServiceHostFactory : NinjectServiceHostFactory
{
public NinjectFileLessServiceHostFactory()
{
var kernel = new StandardKernel(new BusinessModule());
kernel.Bind<ServiceHost>().To<NinjectServiceHost>();
SetKernel(kernel);
}
}
There are a Wcf library and Wcf Console host libraries out there and I understand them. What could the purpose of this library?
Thanks in advance.
In short, due to changes in the hosting environment, IIS hosted WCF is different from console hosted WCF, in the console, we can add additional logic, add additional services, and endpoint behavior before the service is started through ServiceHost event, or initialize the database and so on.
Because IIS does not instantiate Service host, events linked to the service lifecycle are all implemented through the Factory property.
Here is a detailed explanation.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/extending/extending-hosting-using-servicehostfactory
NinjectServiceHostFactory extension adds support for Dedenpency injection for WCF service and behaviors.
https://github.com/ninject/Ninject.Extensions.Wcf
Feel free to let me know If there is anything I can help with.
I want to decorate WCF service with the following setup:
SVC definition
<%# ServiceHost Language="C#" Debug="true"
Service="Foo.IBarService, Foo"
Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf"%>
Autofac registration
builder.RegisterType<FooService>().Named<IFooService>("fooservice");
builder.RegisterType<LogFooService>().Named<IFooService>("logfooservice");
builder
.RegisterDecorator<IFooService>(
(context, inner) => context.ResolveNamed<IFooService>("logfooservice", TypedParameter.From(inner)),
fromKey: "fooservice")
.As<IFooService>();
This approach does work when the decorator is not the service itself. So for example an concrete service with a decorated IWhatever in the constructor. What is different with the svc service?
The docs state:
The standard Autofac service hosting works well for almost every case, but if you are using decorators on your WCF service implementation then you need to use the multitenant WCF service hosting mechanism rather than the standard Autofac service host.
I am using NServiceBus 3.2.7, Castle Windsor 3.1, and ASP.Net MVC 4. I am configuring Windsor currently with the Windsor Tutorial... Windsor tutorial - ASP.NET MVC 3 application
I am unsure how to setup NServiceBus inside this configuration. I'd like to maintain the installer pattern, and I won't be running the host (I believe). Inside this solution is the host process that handles all the messages and it uses the typical Endpointconfiguration with Windsor which handles all the container registrations.
Having the web project send a message was an after thought and I'd like to not have to alter the way I have configured the web project to add NServiceBus in. If anyone can offer up an example of how to do this, that would be fantastic. I figure it would be in a facility similar to the persistence facility in the tutorial, but I am still a little unsure how to do this appropriately.
It turned out to be rather simple.
Simply creating another installer class (since it seems the CastleWindsorBuilder() needed the container passed in. I had tried to create a facility and this was my problem.) I created an installer class like so:
public class NServiceBusInstaller: IWindsorInstaller {
public void Install(IWindsorContainer container, IConfigurationStore store) {
Configure.With()
.DefineEndpointName(ConfigurationManager.AppSettings["InputQueue"])
.CastleWindsorBuilder(container)
.XmlSerializer()
.MsmqTransport()
.UnicastBus()
.SendOnly();
}
}
The AppSettings key is the input queue in which the process host is also expecting messages, so as soon as it sends the message from the controller, it is placed in this queue and the host picks up on it immediately. Also by doing this it allows me to have the proper servers assigned to it as it is deployed to test and production.
Fortunately this was all the configuration I needed in the MVC application to work, I also had to put redirects for Windsor 3.1.
I have a WCF service which programmatically creates its endpoints rather than using a config file - I'm looking into this as our field engineers are prone to break XML easily and we may use different types of binding in different scenarios.
This works well in self-hosted environments (console app, windows app) and as a Windows Service.
Can I do this with a service in IIS or do I have to provide a .SVC file for each endpoint ?
Also will the endpoint address from the client end have to include the .SVC extension ?
This is not a service intended to be used by third parties, only by our client components. We may expose parts of our API later but not initially.
If you're using .NET Framework 4.0 (and later), you can use the ASP.NET routing integration to define a service using a custom ServiceHostFactory implementation. A few things you'll need:
In web.config, set the attribute aspNetCompatibilityEnabled on the <system.serviceModel / serviceHostingEnvironment> element to true
Add a global.asax / global.asax.cs file, and in the Application_Start add a new ServiceRoute to the ASP.NET RouteTable.Routes collection. The service route requres you to define a new service host factory, where you can define your endpoints programmatically.
With that you'll be able to have endpoints without the ".svc" in their addresses. You can also use the service host factory without using routes, by creating a .svc file for each service (not endpoint), and using the Factory attribute in the <%# ServiceHost directive.
For more information about service host factories, check the post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/06/14/wcf-extensibility-servicehostfactory.aspx.
where should I put the code for configuring AutoMapper mapping between DTO and EntityFramework Entities for WCF PerSession services?
If in the default constructor, does that mean every session will create an individual mapping and causes lots of overhead on the server side?
Thanks
Configuration of AutoMapper is global for the whole application so your service should not do any configuration itself. AutoMapper should be configured in your application bootstraper (when the application starts). For example in WCF service hosted in IIS (over HTTP) you can use standard Global.asax and Application_Start.