开发者

Use StructureMap with WCF 4.0 REST Services

How do I use Structure开发者_运维知识库Map in a WCF 4.0 REST service?

I've used StructureMap in the past using this article but the technique doesn't seem to work with the WebServiceHostFactory(). What's the secret?


The method in the previous example article can be made to work by:

  • deriving StructureMapServiceHost from WebServiceHost and not ServiceHost
  • deriving StructureMapServiceHostFactory from WebServiceHostFactory and not ServiceHostFactory

The benefit of this? No web.config changes required. It's all done programatically.


In addition to Alex's instruction, you need to wire up your ServiceHostFactory in the service route of your service instead of using WebServiceHostFactory.

RouteTable.Routes.Add(new ServiceRoute("MemberProvisioning/Api", new IoCServiceHostFactory(), typeof(MemberService)));

Hope this helps.


I got it to work following this example. Essentially you write a customer BehaviorExtension instead of a ServiceHostFactory and life is good.

Would still appreciate any understanding as to why using a custom WebServiceHostFactory doesn't work. It appeared to wire everything up correctly but my IInstanceProvider's GetInstance() method was never being called.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜