クライアントスタブの使用例を次に示します。
この例で呼び出すSPP.NETのサービスメソッドの情報は次のとおりです。
なお,コメント中の(1),(2)などは「4.2.2 クライアントスタブの使用方法」の説明の番号に対応しています。
namespace MyCompany
{
using System;
public interface IGyoumuA
{
void Service1(string dataId, byte[] data);
string[] Service2(string key);
int Service3(int inCount, ref string[] ids);
}
}
using System;
using Hitachi.OpenTP1;
using Hitachi.OpenTP1.Client;
namespace MyCompany
{
public class CallerSample
{
public static void Main(string[] args)
{
try {
TP1Client clt = new TP1Client(); // TP1Clientの生成
IGyoumuAStub server = null;
// (1) クライアントスタブの生成
server = new IGyoumuAStub(clt, "GRP1");
clt.OpenRpc("TP1Host1"); // RPCオープン
clt.OpenConnection(); // 常設コネクションの確立
// (2) 入力データの設定
string[] ids = {"data1", "data2", "data3"};
// (3) 同期応答型RPCに設定
server.Flags = TP1ClientFlags.DCNOFLAGS;
// (4) service3を呼び出す
int ret = server.Service3(3, ref ids);
clt.CloseConnection(); // 常設コネクションの解放
clt.CloseRpc(); // RPCクローズ
} catch (TP1UserException exp) {
// Service3()からユーザ例外がスローされた
} catch (TP1RemoteException exp) {
// Service3()で予期しない例外発生
} catch (TP1ClientException exp) {
// Client .NETが検知したエラー
} catch (TP1Exception exp) {
// その他スタブなど検知したエラー
} catch (Exception exp) {
// 予期しない例外
}
}
}
}
package MyCompany;
import System.*;
import Hitachi.OpenTP1.*;
import Hitachi.OpenTP1.Client.*;
public class CallerSampleImpl
{
public static void main(String[] args)
{
try {
TP1Client clt = new TP1Client(); // TP1Clientの生成
IGyoumuAStub server = null;
// (1) クライアントスタブの生成
server = new IGyoumuAStub(clt, "GRP1");
clt.OpenRpc("TP1Host1"); // RPCオープン
clt.OpenConnection(); // 常設コネクションのオープン
// (2) 入力データの設定
String[] ids = {"data1", "data2", "data3"};
StringArrayHolder idsHolder = new StringArrayHolder();
idsHolder.set_Value(ids);
// (3) 同期応答型RPCに設定
server.set_Flags(TP1ClientFlags.DCNOFLAGS);
// (4) service3を呼び出す
int ret = server.Service3(3, idsHolder);
ids = idsHolder.get_Value();
clt.CloseConnection(); // 常設コネクションのクローズ
clt.CloseRpc(); // RPCクローズ
} catch (TP1UserException exp) {
// Service3()からユーザ例外がスローされた
} catch (TP1RemoteException exp) {
// Service3()で予期しない例外発生
} catch (TP1ClientException exp) {
// Client .NETが検知したエラー
} catch (TP1Exception exp) {
// その他スタブなどが検知したエラー
} catch (System.Exception exp) {
// 予期しない例外
}
}
}
Imports System
Imports Hitachi.OpenTP1
Imports Hitachi.OpenTP1.Client
Namespace MyCompany
Public Class CallerSample
Public Shared Sub Main(ByVal args() As String)
Dim clt As TP1Client
Dim server As IGyoumuAStub
Dim ret As Integer
Dim ids() As String
Try
clt = New TP1Client() ' TP1Clientの生成
' (1) クライアントスタブの生成
server = New IGyoumuAStub(clt, "GRP1")
clt.OpenRpc("TP1Host1") ' RPCオープン
clt.OpenConnection() ' 常設コネクションの確立
' (2) 入力データの設定
ids = New String() {"data1", "data2", "data3"}
' (3) 同期応答型RPCに設定
server.Flags = TP1ClientFlags.DCNOFLAGS
' (4) service3を呼び出す
ret = server.Service3(3, ids)
clt.CloseConnection() ' 常設コネクションの解放
clt.CloseRpc() ' RPCクローズ
Catch exp As TP1UserException
' Service3()からユーザ例外がスローされた
Catch exp As TP1RemoteException
' Service3()で予期しない例外発生
Catch exp As TP1ClientException
' Client .NETが検知したエラー
Catch exp As TP1Exception
' その他スタブなどが検知したエラー
Catch exp As Exception
' 予期しない例外
End Try
End Function
End Class
End Namespace