Israel +972 4 6308447         USA +1 619 831 0029             JAPAN +81 (0)50 5893 6263

OpenLM APIコンサンプションのコンバート(v4 ⇒ v5)

注意:OpenLM Server v5.0以降ではSOAPメソッドはサポートされなくなりました。

次のドキュメントは旧バージョン4.xのAPIを使用したアプリケーションの5.0へのコンバートと調整を説明します。

サンプルプロジェクトを含むこちらのアーカイブを確認する事もできます。

 

目次:

XML APIコンサンプションのコンバート

新しいリンク

コードの変更

SOAP APIコンサンプションのコンバート

新しいリンク

コードの変更

コードサンプル

 

XML APIコンサンプションのコンバート

新しいリンク

http://[openlm_server]:5015/api/easyadminapi/postmessage

 

コードの変更

ポート7014でXML APIを以前使用していた場合は、コードの変更は必要ありません。古いリンク(http://[openlm_server]:7014/OpenLMServer)を新しいリンクに変えてください。全てが通常通り動くはずです。

 

SOAP APIコンサンプションのコンバート

新しいリンク

http://[openlm_server]:5015/api/easyadminapi/web/[method]

 

コードの変更

SOAPメソッドはOpenLM Serverバージョン5.xではもはやサポートされておりません。これらのメソッドを消化するためには、新しいAPIエンドポイントへのウェブリクエストが送られる必要があります。このリクエストはJSONフォーマットで行わなければなりません。レスポンスもJSONフォーマットで返ってきます。下記に旧SOAPメソッドGetDenialsChart をコンバートするコードサンプルを載せました。

 

コードサンプル

using APISamples.AdminAPI;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Net;
using System.Text;


namespace APISamples
{
    class Example
    {
        private const int _port = 5015;
        private const string _server = "localhost";
        private const string UserName = "Please fill user name";
        private const string Password = "Please fill password";


        public void GetTop10DeniedFeaturesInLast30Days()
        {
            var startTime = DateTime.UtcNow.Date.AddDays(-30);
            var endTime = DateTime.UtcNow;


            var request = new DenialChartRequest
            {
                BaseInfo = CreateBaseInfo(),


                GetTrueDenialsOnly = true,
                StartTime = new SlimDateTime()
                {
                    Year = startTime.Year,
                    Month = startTime.Month,
                    Day = startTime.Day
                },


                EndTime = new SlimDateTime()
                {
                    Year = endTime.Year,
                    Month = endTime.Month,
                    Day = endTime.Day,
                    Hour = endTime.Hour,
                    Minute = endTime.Minute,
                    Second = endTime.Second
                },
                GroupBy = "Feature"
            };


            var response = GetDenialsChart(request);
        }


        internal DenialsChartResponse GetDenialsChart(DenialChartRequest request)
        {
            return JsonConvert.DeserializeObject<DenialsChartResponse>(SendRequest(JsonConvert.SerializeObject(request), "GetDenialsChart"));
        }


        internal RequestBaseInfo CreateBaseInfo()
        {
            return new RequestBaseInfo
            {
                PagingData = new PagingData
                {
                    StartRecord = 0,
                    NumOfRecord = 10,
                    Sort = new string[] { "value" },
                    Direction = "desc"
                },


                UserLocalSettings = new UserLocalSettings
                {
                    TimezoneStandardName = "UTC",
                    ThousandsSeparator = ",",
                    DecimalSeparator = ".",
                    TimeFormat = "dd/mm/yyyy hh:mm:ss"
                },
                SessionData = new SessionRefresh { Refresh = true, SessionID = GetSessionID() }
            };
        }


        #region Private methods
        private string SendRequest(string json, string method)
        {
            //string url = "http://localhost:5015/OpenLM.Server.Services/AdminAPI/web/"
            string url = $"http://{_server}:{_port}/OpenLM.Server.Services/AdminAPI/web/{method}";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);


            req.UseDefaultCredentials = true;
            byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(json);
            req.Method = "POST";
            req.ContentType = "text/xml;charset=utf-8";
            req.ContentLength = requestBytes.Length;
            Stream requestStream = req.GetRequestStream();
            requestStream.Write(requestBytes, 0, requestBytes.Length);
            requestStream.Close();


            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);


            string s = System.Text.Encoding.Default.GetString(ASCIIEncoding.Default.GetBytes(sr.ReadToEnd()));
            sr.Close();
            res.Close();


            return s;
        }


        private string GetSessionID()
        {
            LoginFormSettingsResponse response = GetLoginFormSettings();
            if (response.UserAuthenticationRequired)
            {
                return AdminAPIAuthentication(response.ShowWinAuth);
            }
            else//No authentication required
            {
                return string.Empty;
            }
        }


        private UserAuthenticationResponse PerformUserAuthentication(UserAuthenticationRequest request)
        {
            return JsonConvert.DeserializeObject<UserAuthenticationResponse>(GetMessage(JsonConvert.SerializeObject(request), "PerformUserAuthentication"));
        }


        private LoginFormSettingsResponse GetLoginFormSettings()
        {
            var request = new LoginFormSettingsRequest();
            return JsonConvert.DeserializeObject<LoginFormSettingsResponse>(GetMessage(JsonConvert.SerializeObject(request), "GetLoginFormSettings"));
        }


        private string AdminAPIAuthentication(bool useWindowsAuthentication)
        {
            var userAuthenticationRequest = new UserAuthenticationRequest { TrustedAuthentication = useWindowsAuthentication };//Windows authentication 
            if (!useWindowsAuthentication)//OpenLM server authentication 
            {
                userAuthenticationRequest.UserName = UserName;
                userAuthenticationRequest.Password = Password;
            }/* If OpenLM server authentication is required uncheck this code
            else
            {
                userAuthenticationRequest.UserName = UserName;
                userAuthenticationRequest.Password = Password;
                userAuthenticationRequest.TrustedAuthentication = false;
                
            }*/
            UserAuthenticationResponse userAuthenticationResponse = PerformUserAuthentication(userAuthenticationRequest);
            if (userAuthenticationResponse.Error != null)
            {
                throw new Exception(userAuthenticationResponse.Error.Message);
            }
            return userAuthenticationResponse.SessionID;
        }


        private string GetMessage(string message, string method)
        {
            string response = SendRequest(message, method);
            return response;
        }
        #endregion
    }
}
Skip to content