您的位置:首页 > 其它

WCF寄存于Windows服务,通过Form进行调用

2010-12-14 12:13 232 查看
这段时间学习wcf,做了一个小例子,实现了一个产生随机数的wcf服务,寄存于windows服务中,然后通过一个form程序来显示其产生的随机数。

开发工具:VS2010

语言:C#

1.建立3个工程,分别为form(调用wcf服务),wcf服务,windowsservicehost(寄存wcf服务),如下图

form1.cs

LRService.MyServiceClient lrClient = new LRService.MyServiceClient();

private static int rownum = 1;

private void btnGetService_Click(object sender, EventArgs e)
{

lrClient.TimerInit();
lrClient.TimerStart();

MyTimer.Enabled = true;
}

private void MyTimer_Tick(object sender, EventArgs e)
{
if (listBoxMsg.Items.Count >= 200)
{
listBoxMsg.Items.Clear();
rownum = 1;
}

listBoxMsg.Items.Add(rownum.ToString()+":" + lrClient.GetData());
listBoxMsg.SelectedIndex = listBoxMsg.Items.Count - 1;
rownum++;
}

private void btnStop_Click(object sender, EventArgs e)
{
MyTimer.Enabled = false;
}

OK,编译运行即可看到form从寄存于windows服务中的wcf服务读取的随机数:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐