Closed mortenn closed 12 years ago
IIS and Self hosting examples both exist for Normal Services, WebServices and DataServices.
How? I don't write my own svc files..?
A ok I see I missed that you are using a Servcie Libaray instead of an application. I never tried to host a service library. You need to find a way to replace the default ServiceHostFactory by the one provided by NinjectServiceHostFactory.
This blog post might help you http://sankarsan.wordpress.com/2010/06/06/fileless-activation-of-wcf-service-in-net-4-0/ . If you get it working an example would be apprichiated so that others can profit of your work. I don't have the time to do the research how it must be done in this case at the moment. Bringing out the next release has top priority. So don't expect a sample from my side in the near future.
Okay, I have done some research on this today, and either there is a major design flaw in WCF, or I am missing something..
My app.config now has this section:
<serviceHostingEnvironment> <serviceActivations> <add service="Service.TestService" relativeAddress="Service.TestService.svc" factory="Service.NinjectServiceFactory" /> </serviceActivations> </serviceHostingEnvironment>
added to the system.serviceModel section. The custom NinjectServiceFactory class is being called, which binds my types through a NinjectModule.
Using the debugger, all the correct code is called up, but then I get the old familiar:
The service type provided could not be loaded as a service because it does not have a default (parameter-less) constructor. To fix the problem, add a default constructor to the type, or pass an instance of the type to the host.
Going by various questions and blog posts I've found, it is starting to seem like I will have write .svc files by hand - what a pain!
Okay, I am struggling a bit here.. NinjectServiceHostFactory.CreateServiceHost returns a plain ServiceHost with my own type as the only referenced type, from what I can tell inspecting the return value - how is this supposed to work?
No only the return type is ServiceHost but the instance that is returned is a NinjectServiceHost which is derived from ServiceHost.
I'm sorry to say, but it does not appear to be doing that on my computer. I just ran the demo I wrote on IIS, attached to w3wp and set breakpoints on my class, calling the NinjectServiceHostFactory methods. When I in the watch window typed in "host as Ninject.Extensions.Wcf.NinjectServiceHost" the value was null looking at the host object, the watch window says the type is System.ServiceModel.ServiceHost
If I build my own factory, it works fine.. All I do there is return new NinjectServiceHost(Type.GetType(constructorString), baseAddresses);
I am a bit confus why I can't get the NinjectServiceHostFactory to work, any tips?
Using the version available with NuGet, by the way - if that could be relevant.
Okay, I think I sussed it.. I downloaded the 2.2 code and had a look..
Since I don't have any global magic that inherits from NinjectWcfApplication, ServiceHost is never mapped to NinjectServiceHost - so the kernel will just auto-map ServiceHost to ServiceHost!
Not sure I like auto-wiring..
Okay, my sample service library is up and working, got anywhere you want me to upload it?
Thanks for your work on this.
Just fork the project here on github, add the sample and send a pull request.
Okay, that will take me a bit of time, as I'm not currently using git, but I will get on it..
My sample uses separate libraries for the various bits, would you prefer I merge it all together in a single library, or is that ok?
Do like it is better for you
Either way is fine - personally, I separate things like that in keeping with things I picked up from Michele.. But if this is going in as a sample for people using this extension, keeping it in a single library might be easier to get into?
Or should I perhaps refactor the existing sample to split the business logic and contracts out and then reuse the same bits in both the existing samples and the new service library sample?
Your choice, it isn't my project, after all :)
// Cheers, Morten
I don't know your example. So it is hard to decide. Do it the way you think it is easier to understand for others.
Hello, I wrote the sample as a single library.
My intent was to pull out the common bits from the existing examples and have a common dll that all the samples referred. But with how the current samples were implemented, I opted for the faster option, as I didn't want to step on anyones' toes.
My style of coding differs a bit from what I see in the older samples.
If you want, I can revisit the code at a later date and rework all the samples.
-- Regards, Morten
Since the sample has gone in now, I'll close this issue. Please let me know if you want me to rewrite the samples as I described.
// Cheers, Morten
Hi,
I downloaded the zip file and had a look around, and I do not understand how to apply this to a WCF service library. None of my WCF services are hosted in a website or windows application, I merely publish the service library to a web server, letting visual studio create the needed .svc files automatically.
So, I would greatly appreciate it if a sample could be built that uses a WCF service library as a base, rather than a web site.
-- Regards, Morten