Skip to content
赞助合作

本站右侧赞助位长期招租

联系我投放

IOM API 接口调用

Aras Innovator 提供了标准的 SDK 开发类库 IOM(Innovator Object Model)。外部企业系统(ERP、MES 等)或独立的 .NET 程序(控制台、WinForm、Web API 服务)可通过引入 IOM SDK 远程连接并访问 Aras 服务器上的数据。


引入 IOM.dll SDK

在 C# / .NET 项目中,需要引入 Aras 服务器端安装目录下的组件:

  • Aras.IOM.dll

服务器连接与认证

Aras 要求所有连接使用 MD5 哈希后的密码 进行认证,不接受明文密码。完整连接流程如下:

csharp
using Aras.IOM;
using System;

class ArasConnector
{
    static void Main(string[] args)
    {
        // 1. 定义服务器连接参数
        string serverUrl = "http://192.168.1.100/InnovatorServer";
        string dbName = "InnovatorSolutions";
        string userName = "admin";
        string plainPassword = "your_password";
        
        // 2. 将明文密码转换为 MD5 的 32 位小写字符串
        string passwordHash = GetMd5Hash(plainPassword);
        
        // 3. 初始化连接会话
        HttpServerConnection connection = IomFactory.CreateHttpServerConnection(
            serverUrl, dbName, userName, passwordHash);
        
        // 4. 登录验证
        Item loginResult = connection.Login();
        if (loginResult.isError())
        {
            Console.WriteLine($"连接失败:{loginResult.getErrorDetail()}");
            return;
        }
        
        // 5. 实例化操作句柄
        Innovator innovator = new Innovator(connection);
        Console.WriteLine("登录成功,已建立 Innovator 实例会话。");
        
        // 执行数据处理业务...
        
        // 6. 注销会话
        connection.Logout();
    }
    
    private static string GetMd5Hash(string input)
    {
        using (var md5 = System.Security.Cryptography.MD5.Create())
        {
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
            byte[] hashBytes = md5.ComputeHash(inputBytes);
            return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
        }
    }
}

MD5 哈希要求

Aras 的认证机制要求密码为 MD5 32 位小写哈希值。使用 System.Security.Cryptography.MD5 类对明文密码进行哈希处理后再传入连接函数。


基础 CRUD 操作

获得 Innovator 实例后,通过 IOM API 完成数据的增删改查。

查询记录(Read)

csharp
static void QueryParts(Innovator inn)
{
    Item query = inn.newItem("Part", "get");
    query.setAttribute("select", "item_number,name,cost");
    query.setProperty("item_number", "P-10023");
    
    Item result = query.apply();
    
    if (result.isError())
    {
        Console.WriteLine($"未查询到数据:{result.getErrorDetail()}");
        return;
    }
    
    string name = result.getProperty("name");
    string cost = result.getProperty("cost");
    Console.WriteLine($"查询成功 - 零件名: {name}, 成本: {cost}");
}

创建记录(Create)

csharp
static void CreatePart(Innovator inn)
{
    Item part = inn.newItem("Part", "add");
    part.setProperty("item_number", "P-2026-999");
    part.setProperty("name", "二期新增集成零件");
    part.setProperty("cost", "150.00");
    
    Item result = part.apply();
    
    if (result.isError())
    {
        Console.WriteLine($"创建零件失败: {result.getErrorDetail()}");
    }
    else
    {
        Console.WriteLine($"创建零件成功,零件 ID 为: {result.getID()}");
    }
}

更新记录(Update)

更新数据前,必须先获取目标记录的物理主键 id,以定位到具体行:

csharp
static void UpdatePartCost(Innovator inn, string partId, string newCost)
{
    Item partUpdate = inn.newItem("Part", "edit");
    partUpdate.setID(partId);
    partUpdate.setProperty("cost", newCost);
    
    Item result = partUpdate.apply();
    
    if (result.isError())
    {
        Console.WriteLine($"属性修改失败: {result.getErrorDetail()}");
    }
    else
    {
        Console.WriteLine("属性修改成功。");
    }
}

OData REST API 接口调用

Aras v12 及更高版本内置支持了符合 OData v4 标准的 REST API。外部非 .NET 系统(Java、Python、Node.js 等)可以直接通过 HTTP 请求与其交互。

获取 Access Token

使用客户端证书向 /Server/oauth.ashx/token 端点请求认证 Token:

参数
MethodPOST
HeaderContent-Type: application/x-www-form-urlencoded
Bodygrant_type=password&username=admin&password=MD5_PASSWORD&database=InnovatorDB&client_id=IomApp

密码格式

REST API 同样要求传入 MD5 哈希后的密码,而非明文。

发起 OData 数据查询

获取 Bearer Token 后,即可对 OData 端点执行请求:

http
GET /Server/odata/Part('PART_ID') HTTP/1.1
Host: localhost
Authorization: Bearer YOUR_ACCESS_TOKEN
Accept: application/json

OData 端点支持 $select$filter$expand$top$skip 等标准查询参数,用于精确定义返回数据。

本站内容仅供学习与参考

本站总访问量