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 ...
随机推荐
- keil:C语言里面调用汇编程序
C语言直观,汇编效率高,C里面嵌入汇编是很好的选择. 路径大概如图: mian.c是我的C语言程序,Func.s是汇编程序. 主要是Init_1这个函数的实现在汇编文件里面,使用汇编实现的. 首先在C ...
- VS编译常见错误枚举01
fatal error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x0403. Valu ...
- 常用的软件设计模式的Java实现——让编程从野生到飞起
常用的软件设计模式的Java实现——让编程从野生到飞起_野生技术协会_科技_bilibili_哔哩哔哩 https://www.bilibili.com/video/av7596511/
- 游戏引擎架构Note2
[游戏引擎架构Note2] 1.视觉属性(visual property)决定光线如何与物体表面产生交互作用. 2.一个Mesh所使用三角形的多少可以用细致程度(level-of-detail,LOD ...
- mysql视图总结
http://www.2cto.com/database/201508/427083.html 一. 视图概述 视图是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据. ...
- 网页开发中调用iframe中的函数或者是dom元素
iframe中的代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <hea ...
- Python3.7安装PyQt5的方法
一.系统环境 操作系统:Win7 64位 Python Version:3.7 二.安装参考 方法1:pip install PyQt5 方法2:下载whl安装包安装 a.下载网址:https://p ...
- MAC通过SSH使用PEM文件登录
1.命令如下 ssh -i key.pem ssh -i key.pem root@IP 如果出现报错说明这个问题是文件的权限太大了,需要给小点 sudo chmod 600 key.pem 然后再执 ...
- 默默的发现在网上找到的hook NtQueryDirectoryFile......
默默的发现在网上找到的hook NtQueryDirectoryFile...... hook NtQueryDirectoryFile是为了实现文件隐藏,然后就发现在网上发现的代码版本似乎同一个 ...
- 第一次C语言作业:博客随笔
1)你觉得大学和高中有什么差别?具体学习上哪? 大学自主学习较多,锻炼自己独立的品质.在学习上,增加了课程的深度和难度,由更多的活动. 2)我希望大学的师生关系是?阅读上述博客后对师生关系有何感想? ...