クライアントスタブの使用例,およびXMLスキーマ例を次に示します。
この例で呼び出すSPP.NETのサービスメソッドの情報は次のとおりです。
なお,コメント中の(1),(2)などは「3.2.2 クライアントスタブの使用方法」の説明の番号に対応しています。
using System;
namespace MyCompany
{
public interface IGyoumuA
{
void Service1(string dataId, byte[] data);
string[] Service2(string key);
int Service3(int inCount, ref string[] ids);
}
}
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="IGyoumuA_Service3_InData"
type="IGyoumuA_Service3_InData" />
<xs:complexType name="IGyoumuA_Service3_InData">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="inCount"
type="xs:int" />
<xs:element minOccurs="0" maxOccurs="1" name="ids"
type="ArrayOfString" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayOfString">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded"
name="string" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="IGyoumuA_Service3_OutData"
type="IGyoumuA_Service3_OutData" />
<xs:complexType name="IGyoumuA_Service3_OutData">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="ids"
type="ArrayOfString" />
<xs:element minOccurs="1" maxOccurs="1" name="returnValue"
type="xs:int" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayOfString">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded"
name="string" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
using System;
using Hitachi.OpenTP1;
using Hitachi.OpenTP1.Connector;
namespace MyCompany
{
public class MyForm1 : System.Web.UI.Page
{
…
private void Button1_Click(object sender, System.EventArgs e)
{
TP1Connection tc = null;
// このボタンがクリックされたら
// OpenTP1<TP1Host1>のサービス要求を行う
try {
// グローバル変数のアプリケーション状態から
// TP1ConnectionManagerを取得
// (1) TP1ConnectionManagerクラスの生成
TP1ConnectionManager tcm =
(TP1ConnectionManager)this.Application["tcmTP1Host1"];
// (2) TP1Connectionオブジェクトの取得
tc = tcm.GetConnection();
// (3) クライアントスタブの生成
IGyoumuAStub server = new IGyoumuAStub(tc, "GRP1");
// (4) RPC呼び出し形態
server.Flags = RpcInfo.DCNOFLAGS;
// (4) 最大応答待ち時間
server.WatchTime = 180;
// (5) 入力データの設定
string[] ids = new string[]{"data1","data2","data3"};
// (6) Service3を呼び出す
int index = server.Service3(3, ref ids);
// (7) 戻り値,出力パラメタの参照
this.textBox1.Text = ids[index];
} catch (TP1UserException exp) {
// Service3()からユーザ例外がスローされた
} catch (TP1RemoteException exp) {
// Service3()で予期しない例外発生
} catch (TP1ConnectorException exp) {
// Connector .NETが検知したエラー
} catch (TP1Exception exp) {
// その他スタブなどが検知したエラー
} catch (Exception exp) {
// 予期しない例外
}
finally
{
// (8) コネクションをコネクションプールに戻す
if (tc != null) tc.Dispose();
}
}
}
}
package MyCompany;
import System.*;
import Hitachi.OpenTP1.*;
import Hitachi.OpenTP1.Client.*;
public class MyForm1 extends System.Web.UI.Page
{
…
private void Button1_Click(Object sender, System.EventArgs e)
{
TP1Connection tc = null;
// このボタンがクリックされたら
// OpenTP1<TP1Host1>のサービス要求を行う
try {
// グローバル変数のアプリケーション状態から
// TP1ConnectionManagerを取得
// (1) TP1ConnectionManagerクラスの生成
TP1ConnectionManager tcm =
(TP1ConnectionManager)this.get_Application().
Get("tcmTP1Host1");
// (2) TP1Connectionオブジェクトの取得
tc = tcm.GetConnection();
// (3) クライアントスタブの生成
IGyoumuAStub server = new IGyoumuAStub(tc, "GRP1");
// (4) RPC呼び出し形態
server.set_Flags(RpcInfo.DCNOFLAGS);
// (4) 最大応答待ち時間
server.set_WatchTime(180);
// (5) 入力データの設定
StringArrayHolder idsHolder = new StringArrayHolder();
// (5) 入力データの設定
String[] ids = new String[]{"data1","data2","data3"};
// (6) Service3を呼び出す
int index;
// (6) Service3を呼び出す
index = server.Service3(3, idsHolder);
// (7) 戻り値,出力パラメタの参照
this.textBox1.set_Text(idsHolder.get_Value()[index]);
} catch (TP1UserException exp) {
// Service3()からユーザ例外がスローされた
} catch (TP1RemoteException exp) {
// Service3()で予期しない例外発生
} catch (TP1ConnectorException exp) {
// Connector .NETが検知したエラー
} catch (TP1Exception exp) {
// その他スタブなどが検知したエラー
} catch (System.Exception exp) {
// 予期しない例外
}
finally
{
// (8) コネクションをコネクションプールに戻す
if (tc != null) tc.Dispose();
}
}
}
Imports System
Imports Hitachi.OpenTP1
Imports Hitachi.OpenTP1.Connector
Namespace MyCompany
Public Class MyForm1
Inherits System.Web.UI.Page
…
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim tcm As TP1ConnectionManager
Dim tc As TP1Connection
Dim ret As Integer
Dim ids() As String
Dim index As Integer
' このボタンがクリックされたら
' OpenTP1<TP1Host1>のサービス要求を行う
Try
' グローバル変数のアプリケーション状態から
' TP1ConnectionManagerを取得
' (1) TP1ConnectionManagerクラスの生成
tcm = CType(Application("tcmTP1Host1"), _
TP1ConnectionManager)
' (2) TP1Connectionオブジェクトの取得
tc = tcm.GetConnection()
' (3) クライアントスタブの生成
Dim server As IGyoumuAStub = New IGyoumuAStub(tc, "GRP1")
' (4) RPC呼び出し形態
server.Flags = RpcInfo.DCNOFLAGS
' (4) 最大応答待ち時間
server.WatchTime = 180
' (5) 入力データの設定
ids = New String(){"data1","data2","data3"}
' (6) Service3を呼び出す
index = server.Service3(3, ids)
' (7) 戻り値,出力パラメタの参照
textBox1.Text = ids(index)
Catch exp As TP1UserException
' Service3()からユーザ例外がスローされた
Catch exp As TP1RemoteException
' Service3()で予期しない例外発生
Catch exp As TP1ConnectorException
' Connector .NETが検知したエラー
Catch exp As TP1Exception
' その他スタブなどが検知したエラー
Catch exp As Exception
' 予期しない例外
Finally
If Not(tc Is Nothing) Then
' (8) コネクションをコネクションプールに戻す
tc.Dispose()
End If
End Try
End Sub
End Class
End Namespace
using System;
using System.Xml;
using Hitachi.OpenTP1;
using Hitachi.OpenTP1.Connector;
namespace MyCompany
{
public class MyForm1 : System.Web.UI.Page
{
…
private void Button1_Click(object sender, System.EventArgs e)
{
TP1Connection tc = null;
// このボタンがクリックされたら
// OpenTP1<TP1Host1>のサービス要求を行う
try {
// グローバル変数のアプリケーション状態から
// TP1ConnectionManagerを取得
// (1) TP1ConnectionManagerクラスの生成
TP1ConnectionManager tcm =
(TP1ConnectionManager)this.Application["tcmTP1Host1"];
// (2) TP1Connectionオブジェクトの取得
tc = tcm.GetConnection();
// (3) クライアントスタブの生成
IGyoumuAStub server = new IGyoumuAStub(tc, "GRP1");
// (4) RPC呼び出し形態
server.Flags = RpcInfo.DCNOFLAGS;
// (4) 最大応答待ち時間
server.WatchTime = 180;
// (5) 入力データの設定
XmlDocument inDoc = GetInputData();
// (5) 入力データの設定
inDoc.SelectSingleNode("/IGyoumuA_Service3_InData/inCount"
).InnerText = "3";
// (6) Service3ByXmlを呼び出す
XmlDocument outDoc = server.Service3ByXml(inDoc);
// (7) 戻り値,出力パラメタの参照
String index =
outDoc.SelectSingleNode(
"/IGyoumuA_Service3_OutData/returnValue").InnerText;
// (7) 戻り値,出力パラメタの参照
this.textBox1.Text =
outDoc.SelectSingleNode(
"/IGyoumuA_Service3_OutData/ids["+index+"]").InnerText;
} catch (TP1UserException exp) {
// Service3()からユーザ例外がスローされた
} catch (TP1RemoteException exp) {
// Service3()で予期しない例外発生
} catch (TP1ConnectorException exp) {
// Connector .NETが検知したエラー
} catch (TP1Exception exp) {
// その他スタブなどが検知したエラー
} catch (Exception exp) {
// 予期しない例外
}
finally
{
// (8) コネクションをコネクションプールに戻す
if (tc != null) tc.Dispose();
}
}
}
}
package MyCompany;
import System.*;
import System.Xml.*;
import Hitachi.OpenTP1.*;
import Hitachi.OpenTP1.Client.*;
public class MyForm1 extends System.Web.UI.Page
{
…
private void Button1_Click(Object sender, System.EventArgs e)
{
TP1Connection tc = null;
// このボタンがクリックされたら
// OpenTP1<TP1Host1>のサービス要求を行う
try {
// グローバル変数のアプリケーション状態から
// TP1ConnectionManagerを取得
// (1) TP1ConnectionManagerクラスの生成
TP1ConnectionManager tcm =
(TP1ConnectionManager)this.get_Application().
Get("tcmTP1Host1");
// (2) TP1Connectionオブジェクトの取得
tc = tcm.GetConnection();
// (3) クライアントスタブの生成
IGyoumuAStub server = new IGyoumuAStub(tc, "GRP1");
// (4) RPC呼び出し形態
server.set_Flags(RpcInfo.DCNOFLAGS);
// (4) 最大応答待ち時間
server.set_WatchTime(180);
// (5) 入力データの設定
XmlDocument inDoc = GetInputData();
// (5) 入力データの設定
inDoc.SelectSingleNode("/IGyoumuA_Service3_InData/inCount"
).set_InnerText("3");
// (6) Service3ByXmlを呼び出す
XmlDocument outDoc = server.Service3ByXml(inDoc);
// (7) 戻り値,出力パラメタの参照
String index =
outDoc.SelectSingleNode(
"/IGyoumuA_Service3_OutData/returnValue").get_InnerText();
// (7) 戻り値,出力パラメタの参照
this.textBox1.set_Text(
outDoc.SelectSingleNode(
"/IGyoumuA_Service3_OutData/ids["+index+"]"
).get_InnerText());
} catch (TP1UserException exp) {
// Service3()からユーザ例外がスローされた
} catch (TP1RemoteException exp) {
// Service3()で予期しない例外発生
} catch (TP1ConnectorException exp) {
// Connector .NETが検知したエラー
} catch (TP1Exception exp) {
// その他スタブなどが検知したエラー
} catch (System.Exception exp) {
// 予期しない例外
}
finally
{
// (8) コネクションをコネクションプールに戻す
if (tc != null) tc.Dispose();
}
}
}
Imports System
Imports System.Xml
Imports Hitachi.OpenTP1
Imports Hitachi.OpenTP1.Connector
Namespace MyCompany
Public Class MyForm1
Inherits System.Web.UI.Page
…
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim tcm As TP1ConnectionManager
Dim tc As TP1Connection
Dim ret As Integer
Dim ids() As String
Dim index As String
Dim inDoc, outDoc As XmlDocument
' このボタンがクリックされたら
' OpenTP1<TP1Host1>のサービス要求を行う
Try
' グローバル変数のアプリケーション状態から
' TP1ConnectionManagerを取得
' (1) TP1ConnectionManagerクラスの生成
tcm = CType(Application("tcmTP1Host1"), _
TP1ConnectionManager)
' (2) TP1Connectionオブジェクトの取得
tc = tcm.GetConnection()
' (3) クライアントスタブの生成
Dim server As IGyoumuAStub = New IGyoumuAStub(tc, "GRP1")
' (4) RPC呼び出し形態
server.Flags = RpcInfo.DCNOFLAGS
' (4) 最大応答待ち時間
server.WatchTime = 180
' (5) 入力データの設定
inDoc = GetInputData()
' (5) 入力データの設定
inDoc.SelectSingleNode( _
"/IGyoumuA_Service3_InData/inCount").InnerText = "3"
' (6) Service3ByXmlを呼び出す
outDoc = server.Service3ByXml(inDoc)
' (7) 戻り値,出力パラメタの参照
index = outDoc.SelectSingleNode( _
"/IGyoumuA_Service3_OutData/returnValue").InnerText
' (7) 戻り値,出力パラメタの参照
this.textBox1.Text = outDoc.SelectSingleNode( _
"/IGyoumuA_Service3_OutData/ids["+index+"]").InnerText
Catch exp As TP1UserException
' Service3()からユーザ例外がスローされた
Catch exp As TP1RemoteException
' Service3()で予期しない例外発生
Catch exp As TP1ConnectorException
' Connector .NETが検知したエラー
Catch exp As TP1Exception
' その他スタブなどが検知したエラー
Catch exp As Exception
' 予期しない例外
Finally
If Not(tc Is Nothing) Then
' (8) コネクションをコネクションプールに戻す
tc.Dispose()
End If
End Try
End Sub
End Class
End Namespace