开发者

Use StructureMap with WCF 4.0 REST Services

开发者 https://www.devze.com 2023-01-11 00:08 出处:网络
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().

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

精彩评论

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