クライアントスタブの使用例を次に示します。
この例で呼び出すSPP.NETのサービスメソッドの情報は次のとおりです。
なお,コメント中の(1),(2)などは「4.4.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.Server;
namespace MyCompany
{
public class CallerSampleImpl : SPPBase, ICallerSample
{
private IGyoumuAStub server = null;
…
public override void InitializeSPP()
{
// (1) クライアントスタブの生成
server = new IGyoumuAStub("GRP1");
}
public override void FinalizeSPP()
{
server = null;
}
[TP1RpcMethod]
public int CallService3()
{
try {
string[] ids =
// (2) 入力データの設定
new string[3]{"data1", "data2", "data3"};
// (3) 同期応答型RPCに設定
server.Flags = TP1ServerFlags.DCNOFLAGS;
// (4) service3を呼び出す
int ret = server.Service3(3, ref ids);
return ret;
} catch (TP1UserException exp) {
// Service3()からユーザ例外がスローされた
} catch (TP1RemoteException exp) {
// Service3()で予期しない例外発生
} catch (TP1ServerException exp) {
// OpenTP1(クラスライブラリ)が検知したエラー
} catch (TP1Exception exp) {
// その他OpenTP1が検知したエラー
} catch (Exception exp) {
// 予期しない例外
}
}
}
package MyCompany;
import System.*;
import Hitachi.OpenTP1.*;
import Hitachi.OpenTP1.Server.*;
public class CallerSampleImpl
extends SPPBase implements ICallerSample
{
private IGyoumuAStub server = null;
…
public void InitializeSPP() throws TP1ServerException
{
// (1) クライアントスタブの生成
server = new IGyoumuAStub("GRP1");
}
public void FinalizeSPP()
{
server = null;
}
/** @attribute TP1RpcMethod() */
public int CallService3()
{
try {
String[] ids =
// (2) 入力データの設定
new String[]{"data1", "data2", "data3"};
// (2) 入力データの設定
StringArrayHolder idsHolder = new StringArrayHolder();
// (2) 入力データの設定
idsHolder.set_Value(ids);
// (3) 同期応答型RPCに設定
server.set_Flags(TP1ServerFlags.DCNOFLAGS);
// (4) service3を呼び出す
int ret = server.Service3(3, idsHolder);
return ret;
} catch (TP1UserException exp) {
// Service3()からユーザ例外がスローされた
} catch (TP1RemoteException exp) {
// Service3()で予期しない例外発生
} catch (TP1ServerException exp) {
// OpenTP1(クラスライブラリ)が検知したエラー
} catch (TP1Exception exp) {
// その他OpenTP1が検知したエラー
} catch (System.Exception exp) {
// 予期しない例外
}
}
}
Imports System
Imports Hitachi.OpenTP1
Imports Hitachi.OpenTP1.Server
Namespace MyCompany
Public Class CallerSampleImpl
Inherits SPPBase
Implements ICallerSample
Private server As IGyoumuAStub
…
Public Overrides Sub InitializeSPP()
' (1) クライアントスタブの生成
server = New IGyoumuStub("GRP1")
End Sub
Public Overrides Sub FinalizeSPP()
server = Nothing
End Sub
<TP1RpcMethod()> _
Public Function CallService3() As Integer _
Implements ICallerSample.CallerService3
Try
Dim ret As Integer
Dim ids() As String = _
' (2) 入力データの設定
New String(){"data1","data2","data3"}
' (3) 同期応答型RPCに設定
server.Flags = TP1ServerFlags.DCNOFLAGS
' (4) service3を呼び出す
ret = server.Service3(3, ids)
Catch exp As TP1UserException
' Service3()からユーザ例外がスローされた
Catch exp As TP1RemoteException
' Service3()で予期しない例外発生
Catch exp As TP1ServerException
' OpenTP1(クラスライブラリ)が検知したエラー
Catch exp As TP1Exception
' その他OpenTP1が検知したエラー
Catch exp As Exception
' 予期しない例外
End Try
End Function
End Class
End Namespace
using System;
using Hitachi.OpenTP1;
using Hitachi.OpenTP1.Server;
namespace MyCompany
{
public class CallerSample
{
public static void Main(string[] args)
{
try {
IGyoumuAStub server =
// (1) クライアントスタブの生成
new IGyoumuAStub("GRP1");
Rpc.Open(); // RPCオープン
Adm.Complete(); // SUP.NET開始処理完了通知
// (2) 入力データの設定
string[] ids = new string[]{"data1","data2","data3"};
// (3) 同期応答型RPCに設定
server.Flags = TP1ServerFlags.DCNOFLAGS;
// (4) service3を呼び出す
int ret = server.Service3(3, ref ids);
Rpc.Close(); // RPCクローズ
} catch (TP1UserException exp) {
// Service3()からユーザ例外がスローされた
} catch (TP1RemoteException e) {
// Service3()で予期しない例外発生
} catch (TP1ServerException exp) {
// OpenTP1(クラスライブラリ)が検知したエラー
} catch (TP1Exception exp) {
// その他OpenTP1が検知したエラー
} catch (Exception exp) {
// 予期しない例外
}
}
}
}
package MyCompany;
import System.*;
import Hitachi.OpenTP1.*;
import Hitachi.OpenTP1.Server.*;
public class CallerSample
{
public void main(String args[])
{
try {
int ret;
// (1) クライアントスタブの生成
IGyoumuAStub server = new IGyoumuAStub("GRP1");
Rpc.Open(); // RPCオープン
Adm.Complete(); // SUP.NET開始処理完了通知
// (2) 入力データの設定
StringArrayHolder idsHolder = new StringArrayHolder();
// (2) 入力データの設定
String[] ids = new String[]{"data1","data2","data3"};
// (2) 入力データの設定
idsHolder.set_Value(ids);
// (3) 同期応答型RPCに設定
server.set_Flags(TP1ServerFlags.DCNOFLAGS);
// (4) service3を呼び出す
ret = server.Service3(3, idsHolder);
Rpc.Close(); // RPCクローズ
} catch (TP1UserException exp) {
// Service3()からユーザ例外がスローされた
} catch (TP1RemoteException exp) {
// Service3()で予期しない例外発生
} catch (TP1ServerException exp) {
// OpenTP1(クラスライブラリ)が検知したエラー
} catch (TP1Exception exp) {
// その他OpenTP1が検知したエラー
} catch (System.Exception exp) {
// 予期しない例外
}
}
}
Imports System
Imports Hitachi.OpenTP1
Imports Hitachi.OpenTP1.Server
Namespace MyCompany
Public Class CallerSample
Public Shared Sub Main(ByVal args() As String)
Dim ret As Integer
Try
' (1) クライアントスタブの生成
Dim server As IGyoumuAStub = New IGyoumuAStub("GRP1")
Rpc.Open() ' RPCオープン
Adm.Complete() ' SUP.NET開始処理完了通知
Dim ids() As String = _
' (2) 入力データの設定
New String(){"data1","data2","data3"}
' (3) 同期応答型RPCに設定
server.Flags = TP1ServerFlags.DCNOFLAGS
' (4) service3を呼び出す
ret = server.Service3(3, ids)
Rpc.Close() ' RPCクローズ
Catch exp As TP1UserException
' Service3()からユーザ例外がスローされた
Catch exp As TP1RemoteException
' Service3()で予期しない例外発生
Catch exp As TP1ServerException
' OpenTP1(クラスライブラリ)が検知したエラー
Catch exp As TP1Exception
' その他OpenTP1が検知したエラー
Catch exp As Exception
' 予期しない例外
End Try
End Sub
End Class
End Namespace