Aras学习笔记 (28) Aras创建自定义WebService

1、首先使用Visual Studio创建空的Web应用程序或WCF服务应用程序项目。(本文以Web应用程序为例)

2、添加IOM.dll组件引用。

3、添加Web服务(ASMX)

4、将Aras Innovator路径、数据库名称、用户名密码等配置在web.config中,并将提取方法统一写在一个class中。

5、添加构造函数,实现与Aras的连接并实例化Innovator对象。

public ArasWS()
        {
            HttpServerConnection conn = IomFactory.CreateHttpServerConnection(ConfigurationHelper.GetInnovatorServerSiteURL(), ConfigurationHelper.GetDatabaseName(), ConfigurationHelper.GetUserAccount(), ConfigurationHelper.GetPassword());
            if (conn != null)
            {
                Item logResult = conn.Login();
                if (!logResult.isError())
                {
                    innovator = new Innovator(conn);
                }
            }
        } 

6、添加析构函数,释放Innovator对象

~ArasWS()
        {
            if (innovator != null)
            {
                HttpServerConnection conn = (HttpServerConnection)innovator.getConnection();
                conn.Logout();
            }
        }

7、实现根据Part Number提取Part Name的方法。        

 

[WebMethod]
        public string GetPartNameByNo(string PartNo)
        {
            string PartName = "";

            try
            {
                Item item = innovator.newItem("Part", "get");
                item.setProperty("item_number", PartNo);
                item.setProperty("select", "name");
                item = item.apply();

                PartName = item.getProperty("name");
            }
            catch(Exception ex)
            { }

            return PartName;
        }

8、以File System方式发布项目。

9、发布后的目录结构如下。

10、将该目录文件在Innovator Server站点下创建虚拟目录或应用程序。

11、发布后浏览器调用效果如下。

12、如果要支持远程调试,需要在web.config中增加protocols配置。

<webServices>
    <protocols>
        <add name="HttpSoap"/>
        <add name="HttpPost"/>
        <add name="HttpGet"/>
        <add name="Documentation"/>
    </protocols>
</webServices>                    

13、最终效果如下。

BTW,Aras调用外部WebService和调用外部.dll文件类似,有兴趣的请参考 https://www.cnblogs.com/61007257Steven/p/9884345.html  

posted @ 2018-12-18 20:35  无敌师爷IT技术Blog  阅读(397)  评论(0编辑  收藏  举报