[英]Is it possible to change a WCF service's ServiceHostFactory using attributes?
I just came from this question which describes how to set a custom ServiceHostFactory on the .svc
file markup to add some custom functionality. 我只是来自这个问题 ,它描述了如何在.svc
文件标记上设置自定义ServiceHostFactory以添加一些自定义功能。
Now I'm curious. 现在我很好奇。 Can this be done via custom attributes on the .svc.cs
end? 可以通过.svc.cs
端上的自定义属性来完成此操作吗? ie probably something like: 即可能是这样的:
[ServiceContract]
[Factory("MyApp.MyCustomHostFactory")]
public class MyService {
// do backflips
}
I know you can use custom attributes to (inject) custom behavior into services and operations, but this looks like something that's abstracted deeper than what I've seen so far from the likes of IServiceBehavior
and IOperationBehavior
etc etc. 我知道您可以使用自定义属性将自定义行为(注入)到服务和操作中,但这看起来比我从IServiceBehavior
和IOperationBehavior
等之类到目前为止所见的东西抽象得更深。
If it can be done, how should I do it? 如果可以做到,我应该怎么做? What should I use? 我应该使用什么? A simple push in the right direction would be really helpful. 朝正确方向的简单推动将非常有帮助。 :) :)
I think that this is probably something that you should not do via an attribute, as it is something that feels more like a deployment thing and so I would favour doing it in the serviceActivations part of the config file, but in the interest of answering this question... 我认为这可能是您不应该通过属性执行的操作,因为它看起来更像是部署操作,因此我希望在配置文件的serviceActivations部分中执行此操作,但是为了回答这个问题题...
You could create your own attribute - the accepted answer to Simplifying configuration of WCF4 RESTful service routes would be one way of doing it. 您可以创建自己的属性- 简化WCF4 RESTful服务路由的配置的可接受答案将是完成此操作的一种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.