开发者

Different WCF Service Assembly based on Build Definition

Does anyone know how to target a different assembly when specifying your Service class/assembly in a SVC file ServiceHost declaration tag? I want to target a different assembly name based on debug vs release build definitions. Another aspect of this is that I am using Autofac and the AutofacServiceHostFactory to handle DI into my service classes.

I have tried several preprocessor directive approaches but each results in a "The directive 'ServiceHost' can only be specified once". Here is the example code when I get that error.

<% #if DEBUG %>
    <%@ ServiceHost
        Service="MyNamspace.TestService, MyNamspace_DEBUG"
        Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>
<% #else %>
    <%@ ServiceHost
        Service="MyNamspace.TestService, MyNamspace"
        Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>
<% #endif %>

I know I can solve this by having duplicate SVC files for each and then only deploying the appropriate SVC file based on build which is what I am currently doing, but I figure there has to be an easier way. Any/all help is very much appreciated.

I know I could handle this if I wasn't using IIS and SVC files to host my service, but I'd like to keep it IIS hosted if possible.

UPDATE 1 In searching about this more, I ran across this article that talks about using a VirtualPathProvider to dynamically generate svc output. This will probably work for what I want and I probably should ha开发者_开发技巧ve thought about it before. I still feel like there should be an easier way to do this but can't seem to find it. I'll post my how I got this to work if it does indeed work below. If you have a better approach, I'm open to all ideas.

http://social.msdn.microsoft.com/Forums/en/wcf/thread/350f2cb6-febd-4978-ae65-f79735d412db


I suggest using configuration based activation (only WCF 4) and use different config template for debug and release (or use svc for release and config for debug).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜