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 ...
随机推荐
- 清除stoped impdp/expdp job的方法
stoped impdp/expdp job会在dba_datapump_jobs中留下一条记录,显示为not running. 清除stopped job分两种情况: 1) job能够attach ...
- CSS中盒子垂直居中的常用方法
在前端开发过程中,盒子居中是常常用到的.其中 ,居中又可以分为水平居中和垂直居中.水平居中是比较容易的,直接设置元素的margin: 0 auto就可以实现.但是垂直居中相对来说是比较复杂一些的.下面 ...
- CE学习记录1
主题 春节放假终于有空学习下怎么制作外挂啦......学习写外挂大概是我一开始学习计算机的动力吧....只是一直似懂非懂..看教学视频各种不明白为什么....也没有专门的时间学习下怎么写....春节有 ...
- Reading RxJava Marble Diagrams
------>表示一个Observable(承时间推移,由左入右,左边item先发射) ------>上面的图形,表示这个Observable发射的item ------>上的的|( ...
- Android Architecture Components
https://developer.android.com/topic/libraries/architecture/index.html ViewModel 有LiveData Activity 监 ...
- SQL Server2012中的Throw语句尝试 RAISERROR和THROW比较
SQL SERVER2012实现了类似C#抛出异常的Throw语句.相比较于SQL Server2005之前使用@@ERROR,和SQL Server2005之后使用RAISERROR()引发异常都是 ...
- 使用Fuel安装openstack
一.前言 Fuel是OpenStack的开源部署和管理工具.作为OpenStack社区的开发贡献者,它为OpenStack.OpenStack相关社区项目以及OpenStack插件的部署和管理提供了直 ...
- Java c3p0 连接 MySQL
<?xml version="1.0" encoding="UTF-8"?> <!-- 需要导入c3p0驱动jar包和mysql驱动jar包 ...
- 我使用的网址--Hadoop
1.Hadoop 官网下载:http://hadoop.apache.org/releases.html 各版本网址:http://mirror.bit.edu.cn/apache/hadoop/co ...
- PCL 编程多个点云合成
博客转载自:https://blog.csdn.net/sunboyiris/article/details/72636809 pcl::PointCloud<pcl::PointXYZRGBA ...