程序集替换和类继承
名为 Portal.WebServices.TaskListService
的 WCF 服务使用代码隐藏文件 TaskListService.svc.cs
。在此文件中声明一个名为 TaskListService
的类型,该类型继承自 TaskListServiceBase
类型。并实现一个名为ITaskListService
的接口。所以:
TaskListService: TaskListServiceBase, ITaskListService
^ ^ ^
| | |
application separate assembly
我想在网络服务器上部署 TaskListService
once 并将 TaskListServiceBase
和接口放入单独的程序集由托管 TaskListService
的应用程序引用。因此,当我想要添加、删除或更新 Web 服务中的功能时,我只需将新程序集复制到应用程序的 bin 文件夹中。
由于这种情况发生在运行时,我想知道这种做法是否有任何惩罚或警告(除了使用编译时常量等),或者这种情况是否可能< /strong>,或者是否有更好的做法。
所以基本上,我的问题是:我想更新 WCF 服务的功能,而无需重新部署整个应用程序,而只需重新部署更新的程序集< /strong>
(是的,我觉得这里有点愚蠢)
A WCF service named Portal.WebServices.TaskListService
uses a codebehind file TaskListService.svc.cs
. In this file declare a type named TaskListService
that inherits from the type TaskListServiceBase
. and implements an interface named ITaskListService
. So:
TaskListService: TaskListServiceBase, ITaskListService
^ ^ ^
| | |
application separate assembly
I want to deploy the TaskListService
once on the webserver and put TaskListServiceBase
and the interface into a separate assembly that is referenced by the application that hosts TaskListService
. So when I want to add, remove or update functionality in the web service I only have to copy the new assembly into the application's bin folder.
Since this happens during runtime I wonder if there are any penalties or caveats for this practice (besides of the use of compile time constants etc), or if this scenario is even possible, or if there are better practices for doing this.
So basically, my question is: I want to update functionality to a WCF service without redeploying the whole application, only the assembly that is updated
(yes I feel a bit stupid here)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在另一个程序集中分离接口和基类是可能的并且是正确的(分离接口是一种仅针对接口描述这种情况的模式,并且相同的模式适用于基类)。
关于部署,您可以这样做,因为程序集是由 IIS 进行卷影复制的。但是,一旦复制了新程序集,我假设您必须回收应用程序才能加载新程序集。
我为 Windows 服务手动执行此操作,该服务启动了启用卷影复制的独立 AppDomain,因此我可以远程更新程序集并强制重新启动服务。
The separation of interface and base class in another assembly is possible and correct (Separated Interface is a pattern describing this for just interfaces, and the same pattern applies for base classes).
Regarding the deployment, you can do that as the assemblies are shadow-copied by IIS. However, once the new assembly is copied, I assume you have to recycle the application so the new assembly is loaded.
I did this manually for a Windows Service, that launched a separated AppDomain with shadow copy enabled, so I could remotely update an assembly and force a restart of the service.
这是我遵循的做法,据我所知没有任何缺点,只有好处。我更进一步,因为我不使用后面的代码。因此,在上面的示例中,TaskListService.cs 将位于
ServiceImplementations
程序集中,与ServiceContracts
程序集分开。这允许您根据需要将合同/实现分解为多个程序集(可能按域分隔)并独立更新它们。
This is a practice I follow, there are no downsides that I know of, only benefits. I take it one step further, in that I do not use the code behind. So in your example above, TaskListService.cs would live in a
ServiceImplementations
assembly, separate from theServiceContracts
assembly.This allows you to break down your contracts/implementations into multiple assemblies if needed (perhaps separated by domain) and update them independently.