简体   繁体   English

使用WebRole将WCF服务部署到非Azure Hoster

[英]Deploy WCF Service with WebRole to non-Azure Hoster

I have a WCF Service with one WebRole and one WorkerRole for the communication with the Azure database. 我有一个带有一个WebRole和一个WorkerRole的WCF服务,用于与Azure数据库进行通信。 This service is deployed into a Windows Azure Cloud. 此服务部署到Windows Azure云中。 Everything works fine. 一切正常。

But now, I have a (more or less academic) question: Is it possible to deploy this service to another hoster, means not to the Azure Cloud. 但现在,我有一个(或多或少学术性)问题:是否可以将此服务部署到另一个托管服务商,而不是Azure云。 If yes, which parts of the program have to be changed and which software (ie IIS) is need in the other hosting environment. 如果是,则必须更改程序的哪些部分以及在其他托管环境中需要哪些软件(即IIS)。

Background of this question is: My customer wants to know, whether he is independant of the Azure Cloud or not. 这个问题的背景是:我的客户想知道他是否独立于Azure云。

Thanks a lot for your answers! 非常感谢你的回答!

Simple Answer 简单的答案

What happens when you run your code directly in Visual Studio (ie not in the emulator)? 直接在Visual Studio中运行代码时(即不在模拟器中)会发生什么?

Long Answer 答案很长

When you create a Role in Azure, Visual Studio adds a class to your project which inherits RoleEntryPoint. 在Azure中创建角色时,Visual Studio会向项目添加一个继承RoleEntryPoint的类。 This class contains functions for OnStart, OnStop and Run. 该类包含OnStart,OnStop和Run的函数。

For the WebRole, this class is not necessary, in fact the object that is created is in a separate process to your ASP.NET application. 对于WebRole,此类不是必需的,实际上创建的对象与ASP.NET应用程序位于一个单独的进程中。 If you have any code in here, you need to put it somewhere else when you run it on premises (or other cloud). 如果您在此处有任何代码,则需要在内部(或其他云)上运行它时将其放在其他位置。 Perhaps a Windows Service, perhaps Global.asax? 也许是Windows服务,也许是Global.asax?

As for the WorkerRole, it also has a RoleEntryPoint, but this is the main entry point for your application. 至于WorkerRole,它还有一个RoleEntryPoint,但这是你的应用程序的主要入口点。 In this case you could probably create a new Windows Service project in Visual Studio, and re-use the same logic. 在这种情况下,您可以在Visual Studio中创建一个新的Windows服务项目,并重用相同的逻辑。 Whatever code you've put in your 'Run' function, you could probably just move to a shared DLL, which can be accessed from either the WorkerRole or Windows Service. 无论您在“运行”功能中添加了什么代码,您都可以转移到共享DLL,可以从WorkerRole或Windows服务访问该DLL。

As for other Azure features (blobs, queues, tables, SQL Database, Access Control Service, Service Bus etc. etc...), these can still be used from outside Azure, or you could seek an alternative for each. 至于其他Azure功能(blob,队列,表,SQL数据库,访问控制服务,服务总线等等),这些仍可以从Azure外部使用,或者您可以为每个功能寻找替代方案。 For illustrative purposes you could do this: 为了便于说明,您可以这样做:

Queues -> MSMQ 队列 - > MSMQ

Blobs -> File System Blob - >文件系统

SQL Database -> SQL Server SQL数据库 - > SQL Server

If you use the Inversion of Control pattern, you could abstract away the implementation of these technologies, to make your application agnostic of which underlying technology is being used. 如果使用Inversion of Control模式,则可以抽象出这些技术的实现,使您的应用程序不知道正在使用哪种底层技术。 This makes it really easy to switch implementations (and cloud vendors). 这使得切换实现(和云供应商)变得非常容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM