1
votes

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?

2
What do you get when you query the .svc file in your web browser?Christian Hayter
I get a blank HTML page. Then when I hit refresh it says "Service Unavailable".Jacobs Data Solutions
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
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

2 Answers

2
votes

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.

0
votes

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.