views:

577

answers:

2

I'm exploring the possibility of deploying WCF services to a SharePoint Farm/WebApplication/Site/Web via a SharePoint feature without using the SPWebConfigModification class or manually editing web.config. The Gille virtual path fix has already been applied so it doesn't factor into this. The furthest I've been able to get thus far is creating a custom ServiceHostFactory class which I'm referencing inside the .svc file like so:

<%@ ServiceHost Language="C#" Debug="true" Service="Company.Namespace.ServiceClass" Factory="Company.Namespace.CustomServiceHostFactory" %>
<%@ Assembly Name="Company.WCFCustomLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0000000000000000" %>

I'm overriding ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) inside my custom service host factory and applying the various binding/endpoint configuration inside. But the problem I'm running into is that the method isn't even being called when I query the .svc file in my web browser. I was under the impression that IIS will try to create a ServiceHost using the ServiceHostFactory I specified as soon as I call the .svc in my web browser. Am I totally mistaken? Has anybody ever attempted to do something like this before? If so, is there something I'm missing? Is it possible to set up the ServiceHost completely programmatically or do I still have to mess around with <system.serviceModel> tags inside web.config?

A: 

Probably not the answer you are looking for, but I have gone into a bit of detail on how to have WCF-like capability in SharePoint on the SharePoint Depth wiki here. I go into the most detail on using a HttpHandler in lieu of WCF, but I also have some links for full-blown WCF in SharePoint.

In the HttpHandler approach you do not need to modify the root web.config file, but you do need to add a web.config file in your own folder.

I hope this provides some insight.

Kirk Liemohn
Thanks for the link but I'm currently going for full-blown WCF capability in SP. Which at this point in time is not an easy endeavor. Why oh why does SP have to turn everything into a square peg?
Repo Man
A: 

You can do what you want, and get WCF to read configuration from where-ever you like. I built this once, to allow each WCF service to read from its own config file. Good for testing and independent deployment. The technique involves overriding the ServiceHost.ApplyConfiguration method.

This blog post has some additional details and full source code.

Another approach of general interest might be to let the WCF service read its config from a centralized store somewhere - a database, a remote file server, etc. You could use the same basic CustomServiceHost, and just modify one method to load from a database, or whatever.


ps: the reason IIS is disappearing is, I suspect, you have an exception occurring in the WCF ServiceHost.

Cheeso
The above *might* work if I create a custom config file and deploy it to the folder of the feature but ideally I'd like to avoid config files altogether.
Repo Man
that's why I said, you can use the same idea and get your configuration from anywhere.
Cheeso