Communication with each role instance in Azure
Use WCF Communication with role instance in azure
1)In worker role build WCF Service
public override void Run()
{
// This is a sample worker implementation. Replace with your logic.
Trace.TraceInformation("WorkerRole1 entry point called", "Information"); while (true)
{
Thread.Sleep();
Trace.TraceInformation("Working", "Information");
}
}
private ServiceHost serviceHost; private void CreateServiceHost()
{
serviceHost = new ServiceHost(typeof(WcfService)); NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
// RoleInstanceEndpoint externalEndPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["WcfEndpoint"]; string ip = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["WcfEndpoint"].IPEndpoint.Address.ToString();
int tcpport = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["WcfEndpoint"].IPEndpoint.Port; string endpoint = String.Format("net.tcp://{0}:{1}/LoanCalculator", ip, tcpport); //#region insert Instance Information to azure table
//InstanceInformation instance = new InstanceInformation();
//instance.IP = endpoint;
//instance.Port = tcpport;
//// cpu
//System.Diagnostics.PerformanceCounter PC = new System.Diagnostics.PerformanceCounter();
//// instance.CPURate=PC.
//#endregion
serviceHost.AddServiceEndpoint(typeof(IWcfService), binding, endpoint);
try
{
// ServiceLib.AzureTableMethod.InSertInstanceInformation("wcfTable", instance);
serviceHost.Open(); }
catch
{ }
}
public override bool OnStart()
{
// Set the maximum number of concurrent connections
// ServicePointManager.DefaultConnectionLimit = 12;
ServicePointManager.DefaultConnectionLimit = ;
CreateServiceHost();
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. return base.OnStart();
}
2)In Web role build WCF Client
protected void Page_Load(object sender, EventArgs e)
{ } protected void Button1_Click(object sender, EventArgs e)
{
// http://jambor.cloudapp.net/
// string serviceUrl = "net.tcp://jambor.cloudapp.net/LoanCalculator";
// string serviceUrl = String.Format("net.tcp://{0}:{1}/LoanCalculator", "127.0.0.1", "8082");
//string serviceUrl = "net.tcp://207.46.129.69:8082/LoanCalculator";
string address = RoleEnvironment.Roles["WorkerRole1"].Instances[].InstanceEndpoints["WcfEndpoint"].IPEndpoint.Address.ToString();
int tcpport = RoleEnvironment.Roles["WorkerRole1"].Instances[].InstanceEndpoints["WcfEndpoint"].IPEndpoint.Port;
// string d= TextBox2.Text;
string serviceUrl = string.Format("net.tcp://{0}:{1}/LoanCalculator", address, tcpport);
NetTcpBinding binding = new NetTcpBinding(SecurityMode.None); ChannelFactory< IWcfChannel> ChannelFactory = new ChannelFactory<IWcfChannel>(binding, new EndpointAddress(serviceUrl));
IWcfChannel sss = ChannelFactory.CreateChannel();
string oldString = TextBox1.Text;
if (!string.IsNullOrEmpty(oldString.ToString()))
{
Label1.Text = sss.ReverseString(oldString);
}
}
PS: If we need to Use role communication we need to add new endpoint and set type as Internal as following screenshot:
http://www.cnblogs.com/threestone/archive/2012/03/05/2379395.html (之后找到不错的文章)
Communication with each role instance in Azure的更多相关文章
- Windows Azure Cloud Service (10) Role的生命周期
<Windows Azure Platform 系列文章目录> 在上一章内容中,我们提到了Windows Azure会依次调用角色(Role)实例的OnStart()方法和Run()方法. ...
- Windows Azure Cloud Service (11) PaaS之Web Role, Worker Role(上)
<Windows Azure Platform 系列文章目录> 本文是对Windows Azure Platform (六) Windows Azure应用程序运行环境内容的补充. 我们知 ...
- Windows Azure Cloud Service (12) PaaS之Web Role, Worker Role, Azure Storage Queue(下)
<Windows Azure Platform 系列文章目录> 本章DEMO部分源代码,请在这里下载. 在上一章中,笔者介绍了我们可以使用Azure PaaS的Web Role和Worke ...
- Windows Azure Cloud Service (42) 使用Azure In-Role Cache缓存(1)Co-located Role
<Windows Azure Platform 系列文章目录> Update 2016-01-12 https://azure.microsoft.com/zh-cn/documentat ...
- Windows Azure Cloud Service (43) 使用Azure In-Role Cache缓存(2)Dedicated Role
<Windows Azure Platform 系列文章目录> Update 2016-01-12 https://azure.microsoft.com/zh-cn/documentat ...
- [Windows Azure] Building worker role B (email sender) for the Windows Azure Email Service application - 5 of 5.
Building worker role B (email sender) for the Windows Azure Email Service application - 5 of 5. This ...
- [Windows Azure] Building worker role A (email scheduler) for the Windows Azure Email Service application - 4 of 5.
Building worker role A (email scheduler) for the Windows Azure Email Service application - 4 of 5. T ...
- [Windows Azure] Building the web role for the Windows Azure Email Service application - 3 of 5
Building the web role for the Windows Azure Email Service application - 3 of 5. This is the third tu ...
- [Windows Azure] .NET Multi-Tier Application Using Storage Tables, Queues, and Blobs - 1 of 5
.NET Multi-Tier Application Using Storage Tables, Queues, and Blobs - 1 of 5 This tutorial series sh ...
随机推荐
- MongDB安装使用
4.MongoDB 下载 MongoDB 提供了可用于 32 位和 64 位系统的预编译二进制包,你可以从MongoDB官网下载安装,MongoDB 预编译二进制包下载地址:https://www.m ...
- 教你实现GPUImage - OpenGL渲染原理<转>
http://www.open-open.com/lib/view/open1483943550976.html
- ZooKeeper集群搭建过程
ZooKeeper集群搭建过程 提纲 1.ZooKeeper简介 2.ZooKeeper的下载和安装 3.部署3个节点的ZK伪分布式集群 3.1.解压ZooKeeper安装包 3.2.为每个节点建立d ...
- SKNode的渲染顺序
[SKNode的渲染顺序] SKNode的zPosition属性,指定相对于其父视图的z轴坐标. The default value is 0.0. The positive z axis is pr ...
- 因浏览器而异的空白节点(js清除空白节点)
先看下面的代码:<dl id="dll"> <dt>title</dt> <dd>definition</dd>&l ...
- 2-3 JAVA内存模型
- 【HDU4966】GGS-DDU
题意 有n种科目,每个科目都有一个最高的等级a[i].开始的时候,每个科目的等级都是0.现在要选择一些课程进行学习使得每一个科目都达到最高等级.这里有m节课可供选择.对于每门课给出L1[i],c[i] ...
- HtmlHelper扩展
扩展 HtmlHelper类 public static class MyHtmlHelper { //扩展方法 //静态类,静态方法,this关键字 //调用方法<%=Html.MyLabel ...
- NUMA微架构
NUMA微架构 written by qingran September 8th, 2011 no comment 现在开始补日志,逐步的扫清以前写了一半的和"欠账未还的".半年之 ...
- SQL Server 时间类型转换函数
cast ( expression as data_type(length))convert ( data_type (length), expression, style) //如果未指定 leng ...