Deploy WCF Services in SharePoint Without Modifying Web.Config?

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?

13.10.2009 19:22:24
What do you get when you query the .svc file in your web browser?
Christian Hayter 13.10.2009 19:38:11
I get a blank HTML page. Then when I hit refresh it says "Service Unavailable".
Jacobs Data Solutions 13.10.2009 19:58:18
Ok, so it looks like IIS magically shut itself off, which explains why I was getting the "Service Unavailable" message. My CreateServiceHost method is actually being called now but I'm still getting a blank html page when I navigate to server/_vti_bin/myservice.svc, which means that I'm still not correctly configuring all the bindings/endpoints programmatically. Juval book don't fail me now!
Jacobs Data Solutions 13.10.2009 20:46:16
Oh well, that's progress at least. If you get stuck any further, post your programmatic config code here and we will pick it apart for you. :-)
Christian Hayter 14.10.2009 12:42:51
2 ОТВЕТА

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.

0
14.10.2009 03:41:53
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?
Jacobs Data Solutions 14.10.2009 14:26:26

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.

2
14.10.2009 09:11:41
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.
Jacobs Data Solutions 14.10.2009 14:23:10
that's why I said, you can use the same idea and get your configuration from anywhere.
Cheeso 14.10.2009 18:25:01