光CTIスマートコネクトサービスは、以下のWCF APIを提供します。
【サンプルプログラムの利用方法】
1.開発用のパソコンに「光CTIスマートコネクトサービス」をインストールします。
2.Visual Studio Community 2019 を起動し、WinFormアプリ、または、WPFアプリのプロジェクトを作成します。
3.プロジェクト内に以下2つの「サービス参照の追加」をします。
http://localhost:55963/CTI_SmartConnectService/DuplexService/mex
http://localhost:55963/CTI_SmartConnectService/SCS_Service/mex
4.以下の【クライアントプログラムのサンプルソース①②】を参考にプログラムを作成します。
5.以下の【クライアントプログラム用 App.config サンプル】を参考にApp.configファイルを変更します。
6.サービスとやり取りするJSONデータの構造を知るには、以下のファイルを参考にしてください。
・
・
【使用するポート】
- 55963ポート(サービス側のパソコンでオープンが必要です。)
- 80ポート(クライアント側のパソコンでサービス通知[コールバック通信]を利用する場合はオープンが必要です。)
【クライアントプログラムのサンプルソース①】
using System;
using System.ServiceModel;
using System.Windows;
using System.Windows.Threading;
using NotifyIcon;
namespace WpfApp
{
/// <summary>
/// MainWindow.xaml の相互作用ロジック
/// </summary>
[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Single)]
public partial class MainWindow : Window, ServiceReference1.IDuplexServiceCallback
{
private ServiceReference1.DuplexServiceClient _client;
private NotifyIconEx _notify;
private DispatcherTimer _timer;
public MainWindow()
{
InitializeComponent();
}
//SCS接続処理
private bool SCS_Connecting()
{
bool status = false;
try
{
string SvrAddr = "localhost";
//SCSへ接続する
//(WCF双方向通信を行う場合、サービス側にコールバックの実装を教える必要がある。)
var context = new InstanceContext(this);
_client = new ServiceReference1.DuplexServiceClient(context);
_client.Endpoint.Address = new EndpointAddress("http://" + SvrAddr + ":55963/CTI_SmartConnectService/DuplexService/");
_client.Regist(Environment.MachineName + " [user : " + Environment.UserName + "]");
#region キープアライブのためのタイマー処理
//インターバルがTimeSpan型なので注意
this._timer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(300000) //300000ミリ秒=300秒=5分
};
//発生時の処理を記述
this._timer.Tick += (sender, e) =>
{
try
{
//5分に1一度、サーバーへキープアライブ信号を送る。(サーバー側のタイムアウトを防ぐ目的)
if (_client.State == CommunicationState.Opened)
{
_client.KeepAlive(Environment.MachineName + " [user : " + Environment.UserName + "]");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "キープアライブのためのタイマー処理 エラー", MessageBoxButton.OK, MessageBoxImage.Error);
if (_client != null)
{
_client.Abort();
}
}
};
//タイマー開始
this._timer.Start();
#endregion
status = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
if (_client != null)
{
_client.Abort();
}
}
return status;
}
//コールバックの実装(着信記録メッセージ)
public void SendData(string title, string msg)
{
try
{
if (title == "サービスからの通知" && msg == "クライアント生存確認")
{
//バルーン表示(トースト通知)しない
}
else
{
this._notify.ShowBalloonTip(1000, title, msg, ToolTipIconEx.Info);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
//コールバックの実装(着信時コマンド呼出の通知)
public void Notify_CommandCall(string tyakusin_nichiji, string from, string to, long kokyaku_id, string kokyaku_name, string tantou_name, string syubetsu)
{
}
//コールバックの実装(着信時URL呼出の通知)
public void Notify_URLCall(string tyakusin_nichiji, string from, string to, long kokyaku_id, string kokyaku_name, string tantou_name, string syubetsu)
{
}
}
}
【クライアントプログラムのサンプルソース②】
using System;
using System.ServiceModel;
using System.Windows;
using System.Windows.Input;
namespace WpfApp
{
/// <summary>
/// MainWindow.xaml の相互作用ロジック
/// </summary>
public partial class MainWindow : Window
{
private ServiceReference2.SCS_ServiceClient _client;
public MainWindow()
{
InitializeComponent();
}
private async void Btn_Regist_Click(object sender, RoutedEventArgs e)
{
try
{
var result = await this.ShowMessageAsync(this.Title, "この内容で登録してもよろしいですか?", MessageDialogStyle.AffirmativeAndNegative);
if (result == MessageDialogResult.Affirmative)
{
string SvrAddr = "localhost";
//SCSへ接続する
_client = new ServiceReference2.SCS_ServiceClient();
_client.Endpoint.Address = new EndpointAddress("http://" + SvrAddr + ":55963/CTI_SmartConnectService/SCS_Service/");
var tbl = ((収容回線一覧)this.dg_ichiran.DataContext).d_収容回線;
var del = ((収容回線一覧)this.dg_ichiran.DataContext).d_収容回線_削除済み;
var ret = _client.収容回線(
Newtonsoft.Json.JsonConvert.SerializeObject(tbl, Newtonsoft.Json.Formatting.None),
Newtonsoft.Json.JsonConvert.SerializeObject(del, Newtonsoft.Json.Formatting.None));
if (string.IsNullOrEmpty(ret) == true)
{
//登録OK
this.Close();
}
else
{
//登録NG
await this.ShowMessageAsync(this.Title, ret);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
if (_client != null)
{
_client.Abort();
}
}
}
}
}
【クライアントプログラム用 App.config サンプル】
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="WpfSmartConnect.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<system.serviceModel>
<behaviors />
<diagnostics performanceCounters="Default" />
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISCS_Service" sendTimeout="00:10:00"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" transferMode="Streamed">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IDuplexService">
<security mode="None" />
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:55963/CTI_SmartConnectService/SCS_Service/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISCS_Service"
contract="ServiceReference2.ISCS_Service" name="BasicHttpBinding_ISCS_Service" />
<endpoint address="http://localhost:55963/CTI_SmartConnectService/DuplexService/"
binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IDuplexService"
contract="ServiceReference1.IDuplexService" name="WSDualHttpBinding_IDuplexService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
【光CTIスマートコネクトサービスWCF API仕様①】
| アドレス | http://(サービス実行中のパソコンのIPアドレス):55963/CTI_SmartConnectService/SCS_Service/ |
|---|---|
| バインディング | basicHttpBinding |
| データ名称 | コントラクト(オペレーションコントラクト) | |
|---|---|---|
| バージョン | string バージョン() | |
| サービスプログラムのバージョンを文字列で取得します。 | ||
| ライセンス | string ライセンス() | |
| ライセンス状態を文字列で取得します。 | ||
| 認証アクセスコード | string 認証アクセスコード() | |
| 認証アクセスコードを文字列で取得します。 | ||
| 体験モード残日数 | string[] 体験モード残日数() | |
| 体験モードの残日数を文字列配列で取得します。
string[0] = インストール日、string[1] = 残日数、string[2] = 認証状態(True = 認証OK) |
||
| 収容回線 | string 収容回線(string json, string del_json) | |
収容回線の設定をJSONデータで登録&削除、または取得します。
|
||
| SIPサーバー接続設定 | string SIPサーバー接続設定(string json, string del_json) | |
SIPサーバー接続設定の設定をJSONデータで登録&削除、または取得します。
|
||
| 接続中クライアント | string 接続中クライアント() | |
| 接続中クライアントの一覧をJSONデータで取得します。 | ||
| 顧客アドレス帳 | string 顧客アドレス帳(string json, string del_json) | |
顧客アドレス帳の設定をJSONデータで登録&削除、または取得します。
|
||
| 着信記録 | string 着信記録(int top = 0, bool descending = true, long k_id = 0, string [] from = null, string upd_json = null) | |
着信記録の設定をJSONデータで更新、または取得します。
|
||
| 着信時URL呼出 | string 着信時URL呼出(string json, string del_json) | |
着信時URL呼出の設定をJSONデータで登録&削除、または取得します。
|
||
| 着信時コマンド呼出 | string 着信時コマンド呼出(string json, string del_json) | |
着信時コマンド呼出の設定をJSONデータで登録&削除、または取得します。
|
||
| 通知先LINEアクセストークン | string 通知先LINEアクセストークン(string json, string del_json) | |
着信時LINEアクセストークンの設定をJSONデータで登録&削除、または取得します。
|
||
| 通知先メールアドレス | string 通知先メールアドレス(string json, string del_json) | |
通知先メールアドレスの設定をJSONデータで登録&削除、または取得します。
|
||
| 電話番号検索サイト | string 電話番号検索サイト(string json, string del_json) | |
電話番号検索サイトの設定をJSONデータで登録&削除、または取得します。
|
||
| メッセージ定義_メール用 | string メッセージ定義_メール用(string json) | |
メッセージ定義(メール用)の設定をJSONデータで登録、または取得します。
|
||
| メッセージ定義_LINE用 | string メッセージ定義_LINE用(string json) | |
メッセージ定義(LINE用)の設定をJSONデータで登録、または取得します。
|
||
| メッセージ定義_トースト用 | string メッセージ定義_トースト用(string json) | |
メッセージ定義(トースト用)の設定をJSONデータで登録、または取得します。
|
||
| メールアカウント | string メールアカウント(string json) | |
メールアカウントの設定をJSONデータで登録、または取得します。
|
||
| オンラインアクティベーション | string オンラインアクティベーション(string json, string del_json) | |
オンラインアクティベーションの設定をJSONデータで登録&削除、または取得します。
|
||
| データバックアップ | string データバックアップ(string json) | |
データバックアップの設定をJSONデータで登録、または取得します。
|
||
| ユーザー管理 | string ユーザー管理(string json, string del_json) | |
ユーザー管理の設定をJSONデータで登録&削除、または取得します。
|
||
| CSVデータ出力 | string CSVデータ出力(string json) | |
CSVデータ出力の設定をJSONデータで登録、または取得します。
|
||
| EXCELデータ出力 | string EXCELデータ出力(string json) | |
EXCELデータ出力の設定をJSONデータで登録、または取得します。
|
||
| ストリーム受信 (ファイルをローカルへコピー) |
Stream GetStream(string filePath) | |
サーバー(サービスをインストールしたパソコン)のファイルをストリームでローカルにコピーします。
//DBファイルをストリーム受信してローカルに保存する
Stream stm = _client.GetStream("cti_scs.db");
DownloadFileTo(stm, _manual_backup_path);
stm.Close(); stm.Dispose();
private void DownloadFileTo(Stream stm, string fileName)
{
using (var file = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write))
{
int read;
byte[] buffer = new byte[1024];
while ((read = stm.Read(buffer, 0, buffer.Length)) > 0)
{
file.Write(buffer, 0, read);
}
}
}
|
||
【光CTIスマートコネクトサービスWCF API仕様②】
| アドレス | http://(サービス実行中のパソコンのIPアドレス):55963/CTI_SmartConnectService/DuplexService/ |
|---|---|
| バインディング | wsDualHttpBinding |
| データ名称 | コントラクト(オペレーションコントラクト) | |
|---|---|---|
| 接続中クライアントリストへ登録する | void Regist(string name) | |
|
||
| 接続中クライアントリストから登録解除する | void UnRegist(string name) | |
|
||
| キープアライブ(タイムアウトを防ぐため、クライアントから5分間隔で呼び出す) | void KeepAlive(string name) | |
WCFのタイムアウトを防ぐため、クライアントから定期的にキープアライブをコールします。(10分以内に1回コールする必要があります。)
|
||
| データ名称 | コントラクト(コールバックコントラクト) | |
|---|---|---|
| サービスからの通知 | void SendData(string title, string msg) | |
サービスから着信メッセージ、クライアント生存確認、処理完了通知がコールバックされます。
|
||
| 着信時コマンド呼出の通知 | void Notify_CommandCall(string tyakusin_nichiji, string from, string to, long kokyaku_id, string kokyaku_name, string tantou_name, string syubetsu) | |
サービスから着信時コマンド呼出の通知がコールバックされます。
|
||
| 着信時URL呼出の通知 | void Notify_URLCall(string tyakusin_nichiji, string from, string to, long kokyaku_id, string kokyaku_name, string tantou_name, string syubetsu) | |
サービスから着信時URL呼出の通知がコールバックされます。
|
||


