简体   繁体   English

是否可以使用属性更改WCF服务的ServiceHostFactory?

[英]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. 我知道您可以使用自定义属性将自定义行为(注入)到服务和操作中,但这看起来比我从IServiceBehaviorIOperationBehavior等之类到目前为止所见的东西抽象得更深。

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.

相关问题 在WCF服务库项目中使用自定义ServiceHostFactory - Using a custom ServiceHostFactory in a WCF Service Library project 如何为没有SVC文件的自托管WCF服务指定ServiceHostFactory - How to specify ServiceHostFactory for self-hosted WCF service with no SVC file 是否可以使用Mono的XSP Web服务器托管WCF服务? - Is it possible to host a WCF service using Mono's XSP Web server? Sharepoint 2010中的WCF服务找不到我的自定义ServiceHostFactory类 - WCF Service in Sharepoint 2010 can't find my Custom ServiceHostFactory class WCF服务属性被忽略 - WCF Service attributes ignored WCF:NetMsmq而不是Http的应用程序池挂起后,自定义ServiceHostFactory错误 - WCF: Custom ServiceHostFactory errors after Application Pool suspension for NetMsmq but not Http WCF ServiceContract上的“名称”属性可以用于更改服务的URI吗? - Can the “Name” attribute on a WCF ServiceContract be used to change the service's URI? WCF-实施ServiceHostFactory以用于IIS上下文(svc文件) - WCF - Implementing a ServiceHostFactory to use into IIS context (svc file) WCF-使用多个服务证书(由于证书更改) - WCF - Using more than one service certificate (due to certificate change) 使用EF更新WCF服务中的数据库表 - update database's table in WCF service using EF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM