如何在蔚蓝的编程主机WCF服务 [英] How to host wcf service programmatically on azure

查看:177
本文介绍了如何在蔚蓝的编程主机WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想举办在Azure WCF服务,但这一实例必须是动态的,所以我想实例化新的服务但需要...

I want to host a wcf service on Azure, but this instantiation must be dynamic, so I want to instantiate new services as needed however...

新的ServiceHost(新服务(),<<保证到底是什么基础URI>!?>)

什么是应该是基本URI(方案,服务器名和放大器;端口)上:

What's supposed to be the base Uri (Scheme, servername & port) on:


  1. 辅助角色

  2. Web角色

    • 外部端点

    • 内部端点。 (有些服务需要跟对方的背后的负载均衡性能方面的原因,但如何?)

  1. A worker role
  2. A web role
    • External endpoint
    • Internal endpoint. (Some services need to talk to each other behind the load balancer for performance reasons, but how?)

也有这些可能的:


  1. 每个Web角色多个ServiceHost的。

  2. 变端点绑定IE浏览器。我想在HTTP则ServiceHost的,另外的net.tcp如果这样,我需要在部署时的csdef文件中声明这两个协议,或者我可以将其添加为编程需要(亦称后期绑定)?

我要寻找不涉及ServiceBus为$$$原因的解决方案。

I am looking for a solution that doesn't involve ServiceBus for $$$ reasons.

推荐答案

该方法是一样的,无论是在Web角色或Worker角色实例,因为他们都基本上是Windows 2008的服务器(只是Web角色有IIS运行,这也消耗了几个端口)。无论你想在你挂WCF服务的端口,只是这些内容定义为输入端点(每个端口一个端点),并且还可以决定哪个角色处理的终点。

The approach would be the same, whether on Web Role or Worker Role instances, since they're both essentially Windows 2008 Server (just that Web Roles have IIS running, which also consumes a few ports). Whichever port you want to hang your wcf services on, just define these as Input Endpoints (one endpoint per port), and also decide which role handles that endpoint.

只要你有可用端口,你可以有多个ServiceHosts。你目前仅限于25的总输入点和每个部署25总的内部端点,所以这是你的绝对限制。当然,如果您启用RDP,可用端口数量下降。哦:关于协议:如果你想HTTP和TCP,你需要定义两个端点,作为协议与端点定义中定义

As long as you have ports available, you can have multiple ServiceHosts. You're currently limited to 25 total Input Endpoints and 25 total Internal Endpoints per deployment, so this is your absolute limit. Of course, if you enable RDP, the available port count drops. Oh: regarding protocols: If you wanted both http and tcp, you'd need to define two endpoints, as the protocol is defined with the Endpoint definition.

内部端点WCF服务是pretty很多是相同的,但你可以破除的安全和的net.tcp用于快速传输走。在负载均衡,虽然一个区别:

Internal Endpoint WCF Services are pretty much identical, but you can do away with security and go with net.tcp for fast transfer. One difference in load-balancing though:


  • 所有角色的实例的WCF服务挂在一个输入端点将负载平衡

  • WCF服务挂在内部端点会的的进行负载平衡。

  • A WCF service hanging on an Input Endpoint will be load-balanced across all of a role's instance
  • A WCF service hanging on an Internal Endpoint will not be load-balanced.

对于后一种情况:假设你的Web角色需要与内部上端点辅助角色的WCF服务。你需要枚举所有的情况下,得到每个IP +端口,然后选择一个随机(或循环,或任何你选择)。下面是从返回给定角色随机端点实例并给予端点名称(code从迈克尔Washam的的博客):

For the latter case: Let's say your Web Role needs to talk to the Worker Role's WCF service on Internal endpoint. You'd need to enumerate all instances, get the IP+port of each, then select one at random (or round-robin, or whatever method you choose). Here's a sample method that returns a random endpoint instance from a given role and given endpoint name (code borrowed from Michael Washam's blog):

private String GetRandomServiceIP(String roleName, String endPointName)
{
    var endpoints = RoleEnvironment.Roles[roleName].Instances.Select(i => i.InstanceEndpoints[endPointName]).ToArray();
    var r = new Random(DateTime.Now.Millisecond);
    int ipIndex = r.Next(endpoints.Count());
    return endpoints[ipIndex].IPEndpoint.Address.ToString();
}

至于建立WCF服务和相关的URI,我强烈建议抓住最新的 Windows Azure的培训工具包并通过 Worker角色通信走动手实验室,其进入地段有关设置ServiceHost的细节,既有输入端点和内部端点。

As far as setting up the WCF service and related URI, I'd strongly suggest grabbing the latest Windows Azure Training Kit and walking through the Worker Role Communication hands-on lab, which goes into lots of detail about setting up a ServiceHost, with both Input Endpoints and Internal Endpoints.

这篇关于如何在蔚蓝的编程主机WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆