在本课中,您将编译用于自定义验证的包含 Java 或 .NET 逻辑的类。
要执行 Java 同步逻辑,MobiLink 服务器必须有权访问 mlscript.jar 中的类。mlscript.jar 包含要在 Java 方法中使用的 MobiLink Java 服务器 API 类的存储库。编译 Java 类时,将引用 mlscript.jar。
创建一个名为 MobiLinkAuth 的类,并编写 authenticateUser 方法。
MobiLinkAuth 类包括用于 authenticate_user 同步事件的 authenticateUser 方法。authenticate_user 事件可为用户和口令提供参数。在 authentication_status inout 参数中返回验证结果。
您将在第 2 课:为 authenticate_user 事件注册 Java 或 .NET 脚本内注册 authenticate_user 同步事件的 authenticateUser 方法。
为服务器应用程序使用以下代码:
import ianywhere.ml.script.*; public class MobiLinkAuth { public void authenticateUser ( ianywhere.ml.script.InOutInteger authentication_status, String user, String pwd, String newPwd ) { if (user.substring(0,3).equals("128")) { // success: an auth status code of 1000 authentication_status.setValue(1000); } else { // fail: an authentication_status code of 4000 authentication_status.setValue(4000); } } } |
该代码说明一个简单的自定义用户验证情况。当客户端使用以 128 开头的用户名访问统一数据库后,验证成功。
保存您的代码。
此教程将 c:\MLauth 假定为服务器端组件的工作目录。在此目录中,将文件另存为 MobiLinkAuth.java。
编译您的类文件。
浏览到包含 Java 文件的目录。
编译 MobiLinkAuth 类并引用 MobiLink 服务器 Java API 库。
运行以下命令,将 C:\Program Files\SQL Anywhere 12\ 替换为 SQL Anywhere 12 目录:
javac MobiLinkAuth.java -classpath "C:\Program Files\SQL Anywhere 12\java\mlscript.jar" |
将生成 MobiLinkAuth.class 文件。
要执行 .NET 同步逻辑,MobiLink 服务器必须有权访问 iAnywhere.MobiLink.Script.dll 中的类。iAnywhere.MobiLink.Script.dll 包含要在 .NET 方法中使用的 MobiLink .NET 服务器 API 类的存储库。编译 .NET 类时,将引用 iAnywhere.MobiLink.Script.dll。
创建一个名为 MobiLinkAuth 的类,并编写 authenticateUser 方法。
MobiLinkAuth 类包括用于 authenticate_user 同步事件的 authenticateUser 方法。authenticate_user 事件可为用户和口令提供参数。在 authentication_status inout 参数中返回验证结果。
您将在第 2 课:为 authenticate_user 事件注册 Java 或 .NET 脚本内注册 authenticate_user 同步事件的 authenticateUser 方法。
为服务器应用程序使用以下代码:
using iAnywhere.MobiLink.Script; public class MobiLinkAuth { public void authenticateUser( ref int authentication_status, string user, string pwd, string newPwd ) { if(user.Substring(0,3)=="128") { // success: an auth status code of 1000 authentication_status = 1000; } else { // fail: and authentication_status code of 4000 authentication_status = 4000; } } } |
该代码说明一个简单的自定义用户验证情况。当客户端使用以 128 开头的用户名访问统一数据库后,验证成功。
保存您的代码。
此教程将 c:\MLauth 假定为服务器端组件的工作目录。在此目录中,将文件另存为 MobiLinkAuth.cs。
编译您的类文件。
浏览到包含 C# 文件的目录。
编译 MobiLinkAuth 类并引用 MobiLink 服务器 .NET API 库。
运行以下命令,将 C:\Program Files\SQL Anywhere 12\ 替换为 SQL Anywhere 12 目录:
csc /out:MobiLinkAuth.dll /target:library /reference:"C:\Program Files\SQL Anywhere 12\Assembly\v2\iAnywhere.MobiLink.Script.dll" MobiLinkAuth.cs |
将生成 MobiLinkAuth.dll 程序集。
![]() |
使用DocCommentXchange讨论此页。
|
版权 © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |