技术篇(2)--QPG容器的高级用法

我们相信今后的软件都应该主要基于SOA.所以我们的SimpleContainer有一个简单的方法:
DTO handle(string ServiceName,DTO data);
我们调用这个方法去执行我们想要的服务就行了.如果服务在本进程内,那就会直接调用,否则平台会执行远程调用,先把请求发到信息队列中,然后远程服务程序处理,把结果放到队列中.
下面代码示意如何简单享受服务:

using QPG.Utility;
using QPG;
using QPG.Demo.Services;



private SimpleContainer container;
        
public Form1()
        
{
            
//
            
// Windows 窗体设计器支持所必需的
            
//
            InitializeComponent();

                
            Hashtable ht
=new Hashtable();
            ht.Add(
"qpg.calculate_service",typeof(FormulaDynamicCompileService));
        
            container 
= new SimpleContainer(ht);
            random
=new Random();
            
        }



private void button1_Click(object sender, System.EventArgs e) {
            DTO d
=new DTO();
            Parameter[] ps
=new Parameter[3];
            ps[
0]=new Parameter("F(x,y)",txtFxy.Text);
            ps[
1]=new Parameter("x",random.Next(1,20));
            ps[
2]=new Parameter("y",random.Next(1,20));
            lbData.Text
="x="+ps[1].Value+";"+"y="+ps[2].Value;
            d.setInputData(ps,
null);
            d
=container.handle("qpg.calculate_service",d);
            txtResult.Text
=new ParametersHelper(d.ResponseArgs).ToString();
            
        }

为了执行演示请大家
1) 确保机器已经联网(LAN);
2) 转入bin目录;
3) 执行MMQ.exe
4) 执行RemoteServer.exe
5) 执行Local.exe,点击"性能测试",

如果没有问题,再执行多一个RemoteServer.exe,点击"本地计算"和"远程服务",,看看发生了什么?
如果明白了,可以把两个RemoteServer.exe都关闭,在Local上然后"远程服务"2次,再运行RemoteServer.exe,是否看到邮件发送的提示了!

如果运行没有问题,赶紧看看代码是怎么写的吧.https://files.cnblogs.com/QPG2006/QPG_DEMO.zip
由于时间仓忙,所以有问题请提出来,我再完善.

posted @ 2005-10-06 22:03  成为-行动-拥有(BeDoHave)  阅读(1163)  评论(1编辑  收藏  举报