Rules engine Visual Rules Solution development basic tutorial [serial 4]--VRS related calls

VRS related calls


1. Java class
         makes a HelloServer class in Eclipse through the rule service call, receives the parameter input name in the main, calls the hello rule package through the port form of the rule service, and displays the returned welcome speech.
         First of all, you need to check whether the Rule Engine Server service of the server is enabled. In order to start the Rule Engine Server normally, you first need to set the Java path:

1. Set the JAVA_HOME variable
         in the Windows environment, set the system environment variable, add a JAVA_HOME variable, and set it For the jre directory under the VisualRules installation directory. If the JDK is already installed, it can be set to the installation directory of the JDK.





2. Start the Rule Engine Server
         Start the Rule Engine Server service in the system's services:




3. Set the java project path
         First, in the java project of eclipse, click Properties to set its path. Set Libraries in the Java Build Path of its properties window, and add json-lib-2.3-jdk1.3.jar and jdom.jar under lib in the VisualRules installation directory through Add External JARs…. As follows:




4. Add a Java test class
Add a java class to the java project named HelloServer.java, whose content is edited as follows:
import com.flagleader.engine.RuleService;
import com.flagleader.engine.impl.RuleServerPoolFactory;
public class HelloServer {
public static void main(String[] args) {
try {
RuleServerPoolFactory factory = RuleServerPoolFactory.getFactory("localhost", 1508) ;
RuleService service = factory.getRuleService() ;
service.put("name","test communication");
service.execute("hello") ;
System.out.println(service.getString("welcome")) ;
} catch (Exception e) {
e.printStackTrace() ;
}
}
}

5. Execute the java test class
          after clicking and executing , you can see the following results:





          It means that the hello rule package has been called, and according to the incoming name value "access test", the returned processing result is hello + "test communication".
          Similarly, any other java class can complete the work of calling the rule package by adding the above code.
          Second, the Java class makes a HelloSoap class in Eclipse

through SOAP call , passes the name parameter to the rule service, and calls the hello rule package to display the returned welcome speech.           First, you need to check whether the Apache Tomcat rules service of the server is enabled, and you need to ensure that there is a soap project under the default installed Tomcat project :






          Note that the hello.rsc generated in the rules directory of the VisualRules installation directory should be copied to the webapps\soap\WEB-INFO\classes directory of tomcat, so that the rule package can be accessed through the axis.
          Start the Apache Tomcat rules service in the system's services:




1. Set the java project path
          First, in the java project of eclipse, click Properties to set its path. Set Libraries in the Java Build Path of its properties window, and add json-lib-2.3-jdk1.3.jar, jdom.jar, axis.jar, commons-discovery-0.2 under lib under the VisualRules installation directory through Add External JARs... .jar, commons-logging.jar, jaxrpc.jar, mail.jar, saaj.jar, wsdl4j-1.5.1.jar, xerces.jar, xml-apis.jar. As follows:




2.添加Java测试类
          在java工程中添加一个java类,名为HelloSoap.java,其内容编辑如下:
import com.flagleader.engine.RuleService;
import com.flagleader.engine.impl.RuleSoapFactory;
public class HelloSoap {
public static void main(String[] args) {
try {
RuleSoapFactory factory = new
RuleSoapFactory("http://localhost:8880/soap/services/RuleSoap","") ;
RuleService service = factory.getRuleService() ;
service.put("name","测试通讯");
service.execute("hello") ;
System.out.println(service.getString("welcome")) ;
} catch (Exception e) {
e.printStackTrace() ;
}
}
}

3.执行java测试类
          点击执行后,可以看到如下结果:




          说明已经调用了hello规则包,并且根据传入的name值“访问测试”,返回处理结果是 hello+“测试通讯”。

三、C#通过规则服务调用
          在VS中制作一个HelloServer类,将姓名参数传递给规则服务,并调用hello规则包,显示返回的欢迎辞。
1.新建C#工程
          在VS中,新建一个名为HelloServer的控制台应用程序的工程:




2.添加引用
          将RuleEngine.dll添加到引用中。该文件一般位于VisualRules安装目录的samples\notnet\RuleEngine\bin\Release目录下:




3.编写Program.cs
          代码如下,其中192.168.19.128为服务器地址:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RuleEngine;
namespace HelloServer
{
    class Program
    {
        static void Main(string[] args)
        {
            RuleServerPoolFactory factory = RuleServerPoolFactory.getFactory("192.168.19.128", 1508);
            RuleService service = factory.RuleService;
            service.put("name", "测试Socket访问");
            service.execute("hello");

            Console.WriteLine( service.getString("welcome") );
            Console.Read();
        }
    }
}

4.执行测试类
          点击执行后,看到执行结果如下,说明已经调用规则包成功:




四、C#通过SOAP调用
          在VS中制作一个HelloSoap类,将姓名参数传递给规则服务,并调用hello规则包,显示返回的欢迎辞。
1.新建C#工程
          在VS中,新建一个名为HelloSoap的控制台应用程序的工程:





2.添加引用
          将RuleEngine.dll添加到引用中。该文件一般位于VisualRules安装目录的samples\notnet\RuleEngine\bin\Release目录下:




3.添加服务引用




          然后输入Soap服务所在的地址,在地址栏中输入http://192.168.1.121:8880/soap/services/RuleSoap?wsdl 。
          点击“前往”后,可以看到规则服务提供的接口。
          输入一个命名空间后,点击确认。





4.编写Program.cs
          在此中输入三个类,RuleSoapFactory、RuleSoapService、Program,其中RuleSoapFactory、RuleSoapService是对规则调用接口的实现。其他程序都可以像Program操作的那样,调用规则包。:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RuleEngine;
namespace HelloSoap
{
    public class RuleSoapFactory : RuleServiceFactory
    {
        override public RuleService RuleService
        {
            get
            {
                return new RuleSoapService(this);
            }
        }
        public RuleSoapFactory()
            : base()
        {
        }
        public virtual void close()
        {
        }
        public virtual void forceClose()
        {
            this.close();
        }
        public virtual void open()
        {
        }
    }
    public class RuleSoapService : AbstractRuleService
    {
        private RuleSoapFactory Factory
        {
            get
            {
                return (RuleSoapFactory)factory;
            }
        }
        public RuleSoapService(RuleSoapFactory factory)
            : base(factory)
        {
        }
        protected override System.String send(System.String xml)
        {
            try
            {
                HelloSoap.ServiceReference1.RuleSoapClient soap = new HelloSoap.ServiceReference1.RuleSoapClient();
                return soap.getRule(xml);
            }
            catch (System.Exception e)
            {
                Factory.forceClose();
                throw new RuleServiceException(e);
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            RuleSoapFactory factory = new RuleSoapFactory();
            RuleService service = factory.RuleService;
            service.put("name", "测试Soap访问");
            service.execute("hello");
            Console.WriteLine(service.getString("welcome"));
            Console.Read();
        }
    }
}

5.执行测试类
          点击执行后,看到执行结果如下,说明已经调用规则包成功:




          以上实例讲述了如何使用VisualRules,此例子主要是讲述了VisualRules是如何和其他系统接口的。关于如何采用VisualRules进行更深入的功能开发,可以参考其他的教程说明,详细了讲述了如何开发一个对数据库操作的管理系统。可以通过查看《旗正商业规则定制平台基础教程》了解如何通过VisualRules开发基于数据库的管理系统。了解使用VisualRules开发基于数据库管理系统的快捷。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326910633&siteId=291194637