/
ServiceForSb.cs
611 lines (497 loc) · 25.9 KB
/
ServiceForSb.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
//**********************************************************************************
//* Copyright (C) 2007,2016 Hitachi Solutions,Ltd.
//**********************************************************************************
#region Apache License
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion
//**********************************************************************************
//* クラス名 :ServiceForSb
//* クラス日本語名 :ASP.NET Webサービス(サービス インターフェイス基盤)
//* Soap & Bean の個別Webメソッドを公開する。
//*
//* 作成日時 :-
//* 作成者 :sas 生技
//* 更新履歴 :
//*
//* 日時 更新者 内容
//* ---------- ---------------- -------------------------------------------------
//* 2011/12/02 西野 大介 新規作成
//* 2011/12/08 西野 大介 その他、一般的な例外も文字列化して戻す。
//**********************************************************************************
using System.EnterpriseServices;
// System
using System;
using System.IO;
using System.Xml;
using System.Data;
using System.Collections;
using System.Reflection;
// System.Web
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
// 業務フレームワーク
using Touryo.Infrastructure.Business.Common;
using Touryo.Infrastructure.Business.Util;
// フレームワーク
using Touryo.Infrastructure.Framework.Business;
using Touryo.Infrastructure.Framework.Common;
using Touryo.Infrastructure.Framework.Dao;
using Touryo.Infrastructure.Framework.Exceptions;
using Touryo.Infrastructure.Framework.Presentation;
using Touryo.Infrastructure.Framework.Util;
using Touryo.Infrastructure.Framework.Transmission;
// 部品
using Touryo.Infrastructure.Public.Db;
using Touryo.Infrastructure.Public.IO;
using Touryo.Infrastructure.Public.Log;
using Touryo.Infrastructure.Public.Str;
using Touryo.Infrastructure.Public.Util;
namespace Touryo.Infrastructure.Framework.ServiceInterface.ASPNETWebService
{
// 名前空間は、必要に応じて書き換え下さい。
/// <summary>
/// ASP.NET Webサービス(サービス インターフェイス基盤)
/// Soap & Bean の個別Webメソッドを公開する。
/// </summary>
[WebService(Namespace = FxLiteral.WS_NAME_SPACE)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ServiceForSb : System.Web.Services.WebService
{
#region グローバル変数
/// <summary>インプロセス呼び出しの名前解決シングルトン クラス</summary>
/// <remarks>
/// 初期化は起動時の1回のみであり、
/// 読み取り専用のデータを保持する場合
/// のみに適用するデザインパターンとする。
/// </remarks>
private static InProcessNameService IPR_NS = new InProcessNameService();
#endregion
#region コンストラクタ
public ServiceForSb()
{
//デザインされたコンポーネントを使用する場合、次の行をコメントを解除してください
//InitializeComponent();
}
#endregion
#region 個別部
/// <summary>SelectCount</summary>
/// <param name="context">コンテキスト</param>
/// <param name="actionType">アクションタイプ</param>
/// <param name="returnValue">戻り値</param>
/// <returns>返すべきエラーの情報</returns>
[WebMethod(BufferResponse = true, CacheDuration = 0, Description = "SelectCount", EnableSession = true, MessageName = "", TransactionOption = TransactionOption.NotSupported)]
public string SelectCount(ref string context, string actionType, out int returnValue)
{
object temp = null;
string ret = Call(ref context, "sbWebService", "SelectCount", actionType, null, out temp);
if (!int.TryParse((string)temp, out returnValue))
{
returnValue = -1;
}
return ret;
}
/// <summary>SelectAll_DT</summary>
/// <param name="context">コンテキスト</param>
/// <param name="actionType">アクションタイプ</param>
/// <param name="returnValue">戻り値</param>
/// <returns>返すべきエラーの情報</returns>
[WebMethod(BufferResponse = true, CacheDuration = 0, Description = "SelectAll_DT", EnableSession = true, MessageName = "", TransactionOption = TransactionOption.NotSupported)]
public string SelectAll_DT(ref string context, string actionType, out Shipper[] returnValue)
{
object temp = null;
string ret = Call(ref context, "sbWebService", "SelectAll_DT", actionType, null, out temp);
returnValue = (Shipper[])temp;
return ret;
}
/// <summary>SelectAll_DS</summary>
/// <param name="context">コンテキスト</param>
/// <param name="actionType">アクションタイプ</param>
/// <param name="returnValue">戻り値</param>
/// <returns>返すべきエラーの情報</returns>
[WebMethod(BufferResponse = true, CacheDuration = 0, Description = "SelectAll_DS", EnableSession = true, MessageName = "", TransactionOption = TransactionOption.NotSupported)]
public string SelectAll_DS(ref string context, string actionType, out Shipper[] returnValue)
{
object temp = null;
string ret = Call(ref context, "sbWebService", "SelectAll_DS", actionType, null, out temp);
returnValue = (Shipper[])temp;
return ret;
}
/// <summary>SelectAll_DR</summary>
/// <param name="context">コンテキスト</param>
/// <param name="actionType">アクションタイプ</param>
/// <param name="returnValue">戻り値</param>
/// <returns>返すべきエラーの情報</returns>
[WebMethod(BufferResponse = true, CacheDuration = 0, Description = "SelectAll_DR", EnableSession = true, MessageName = "", TransactionOption = TransactionOption.NotSupported)]
public string SelectAll_DR(ref string context, string actionType, out Shipper[] returnValue)
{
object temp = null;
string ret = Call(ref context, "sbWebService", "SelectAll_DR", actionType, null, out temp);
returnValue = (Shipper[])temp;
return ret;
}
/// <summary>SelectAll_DSQL</summary>
/// <param name="context">コンテキスト</param>
/// <param name="actionType">アクションタイプ</param>
/// <param name="orderColumn">orderColumn</param>
/// <param name="orderSequence">orderSequence</param>
/// <param name="returnValue">戻り値</param>
/// <returns>返すべきエラーの情報</returns>
[WebMethod(BufferResponse = true, CacheDuration = 0, Description = "SelectAll_DSQL", EnableSession = true, MessageName = "", TransactionOption = TransactionOption.NotSupported)]
public string SelectAll_DSQL(ref string context, string actionType, string orderColumn, string orderSequence, out Shipper[] returnValue)
{
object temp = null;
string ret = Call(ref context, "sbWebService", "SelectAll_DSQL", actionType,
new string[] { orderColumn, orderSequence }, out temp);
returnValue = (Shipper[])temp;
return ret;
}
/// <summary>Select</summary>
/// <param name="context">コンテキスト</param>
/// <param name="actionType">アクションタイプ</param>
/// <param name="shipperID">shipperID</param>
/// <param name="returnValue">戻り値</param>
/// <returns>返すべきエラーの情報</returns>
[WebMethod(BufferResponse = true, CacheDuration = 0, Description = "Select", EnableSession = true, MessageName = "", TransactionOption = TransactionOption.NotSupported)]
public string Select(ref string context, string actionType, int shipperID, out Shipper returnValue)
{
object temp = null;
string ret = Call(ref context, "sbWebService", "Select", actionType, shipperID, out temp);
returnValue = (Shipper)temp;
return ret;
}
/// <summary>Insert</summary>
/// <param name="context">コンテキスト</param>
/// <param name="actionType">アクションタイプ</param>
/// <param name="companyName">companyName</param>
/// <param name="phone">phone</param>
/// <param name="returnValue">戻り値</param>
/// <returns>返すべきエラーの情報</returns>
[WebMethod(BufferResponse = true, CacheDuration = 0, Description = "Insert", EnableSession = true, MessageName = "", TransactionOption = TransactionOption.NotSupported)]
public string Insert(ref string context, string actionType, string companyName, string phone, out int returnValue)
{
object temp = null;
string ret = Call(ref context, "sbWebService", "Insert", actionType,
new string[] { companyName, phone }, out temp);
if (!int.TryParse((string)temp, out returnValue))
{
returnValue = -1;
}
return ret;
}
/// <summary>Update</summary>
/// <param name="context">コンテキスト</param>
/// <param name="actionType">アクションタイプ</param>
/// <param name="shipper">shipper</param>
/// <param name="returnValue">戻り値</param>
/// <returns>返すべきエラーの情報</returns>
[WebMethod(BufferResponse = true, CacheDuration = 0, Description = "Update", EnableSession = true, MessageName = "", TransactionOption = TransactionOption.NotSupported)]
public string Update(ref string context, string actionType, Shipper shipper, out int returnValue)
{
object temp = null;
string ret = Call(ref context, "sbWebService", "Update", actionType, shipper, out temp);
if (!int.TryParse((string)temp, out returnValue))
{
returnValue = -1;
}
return ret;
}
/// <summary>Delete</summary>
/// <param name="context">コンテキスト</param>
/// <param name="actionType">アクションタイプ</param>
/// <param name="shipperID">shipperID</param>
/// <param name="returnValue">戻り値</param>
/// <returns>返すべきエラーの情報</returns>
[WebMethod(BufferResponse = true, CacheDuration = 0, Description = "Delete", EnableSession = true, MessageName = "", TransactionOption = TransactionOption.NotSupported)]
public string Delete(ref string context, string actionType, int shipperID, out int returnValue)
{
object temp = null;
string ret = Call(ref context, "sbWebService", "Delete", actionType, shipperID, out temp);
if (!int.TryParse((string)temp, out returnValue))
{
returnValue = -1;
}
return ret;
}
#endregion
#region 共通部
/// <summary>Soap & Bean の個別Webメソッドの共通部</summary>
/// <param name="context">コンテキスト</param>
/// <param name="methodName">メソッド名</param>
/// <param name="parameterValue">引数Bean(個別・・・サブ)</param>
/// <param name="returnValue">戻り値Bean(個別・・・サブ)</param>
/// <returns>返すべきエラーの情報</returns>
private string Call(ref string context, string serviceName, string methodName, string actionType, object parameterValue, out object returnValue)
{
// ステータス
string status = "-";
// 初期化のため
returnValue = "";
#region 呼出し制御関係の変数
// アセンブリ名
string assemblyName = "";
// クラス名
string className = "";
#endregion
#region 引数・戻り値関係の変数
// 引数・戻り値の.NETオブジェクト
MuParameterValue muParameterValue = null;
MuReturnValue muReturnValue = null;
// エラー情報(XMLフォーマット)
XmlDocument wsErrorInfo = new XmlDocument();
XmlElement wsErrorRoot = null;
XmlElement wsErrorItem = null;
// エラー情報(ログ出力用)
string errorType = ""; // 2009/09/15-この行
string errorMessageID = "";
string errorMessage = "";
string errorToString = "";
#endregion
try
{
// 開始ログの出力
LogIF.InfoLog("SERVICE-IF", FxLiteral.SIF_STATUS_START);
#region 名前解決
// ★
status = FxLiteral.SIF_STATUS_NAME_SERVICE;
// 名前解決(インプロセス)
ServiceForSb.IPR_NS.NameResolution(serviceName, out assemblyName, out className);
#endregion
#region 引数の.NETオブジェクト化(UOC)
// ★
status = FxLiteral.SIF_STATUS_DESERIALIZE;
// ★★ 引数の.NETオブジェクト化をUOCする(必要に応じて)。
// 引数文字列の.NETオブジェクト化
// string[] cmnParameterValueを使用して初期化するなど
muParameterValue = new MuParameterValue(
"", //cmnParameterValue[0], // 画面名
"", //cmnParameterValue[1], // ボタン名
methodName, //cmnParameterValue[2], // メソッド名
actionType, //cmnParameterValue[3], // アクションタイプ
new MyUserInfo(context, HttpContext.Current.Request.UserHostAddress));
// parameterValueを引数の文字列フィールドに設定
muParameterValue.Bean = parameterValue;
// 引数クラスをパラメタ セットに格納
object[] paramSet = new object[] { muParameterValue, DbEnum.IsolationLevelEnum.User };
#endregion
#region 認証処理(UOC)
// ★
status = FxLiteral.SIF_STATUS_AUTHENTICATION;
//// ★★ 認証が通っているかどうか確認する。
//if (!HttpContext.Current.Request.IsAuthenticated)
//{
// throw new BusinessSystemException("Authentication", "認証されていません。");
//}
// ★★ コンテキストの情報を使用するなどして
// 認証処理をUOCする(必要に応じて)。
//// 認証チケットの復号化
//string[] authTicket = (string[])BinarySerialize.BytesToObject(
// CustomEncode.FromBase64String(
// SymmetricCryptography.DecryptString(
// context, GetConfigParameter.GetConfigValue("private-key"),
// EnumSymmetricAlgorithm.TripleDESCryptoServiceProvider)));
//// ユーザIDの設定
//muParameterValue.User.UserName = authTicket[0];
// 認証チケットの整合性を確認
// Forms認証では、machinekeyを使用している。
// 必要に応じて認証サービス側も作り変える。
//// B層・D層呼出し
//// タイムスタンプのチェックと、更新
//// スライディング・タイムアウトの実装、
//// 必要であればアカウントの検証も実施
//BaseReturnValue _returnValue = (BaseReturnValue)Latebind.InvokeMethod(
// "xxxx", "yyyy",
// FxLiteral.TRANSMISSION_INPROCESS_METHOD_NAME,
// new object[] { new AuthParameterValue("-", "-", "zzzz", "",
// muParameterValue.User, authTicket[1]),
// DbEnum.IsolationLevelEnum.User });
//if (_returnValue.ErrorFlag)
//{
// // 認証エラー
// throw new BusinessSystemException("xxxx", "認証チケットが不正か、タイムアウトです。");
//}
// 持ち回るならCookieにするか、
// contextをrefにするなどとする。
context = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"); // 更新されたかのテストコード
#endregion
#region B層・D層呼出し
// ★
status = FxLiteral.SIF_STATUS_INVOKE;
try
{
// B層・D層呼出し
//// DLL名も指定するパターン(別DLLに含まれる)
//muReturnValue = (MuReturnValue)Latebind.InvokeMethod(
// assemblyName, className, FxLiteral.TRANSMISSION_INPROCESS_METHOD_NAME, paramSet);
// DLL名は指定しないパターン(ExecutingAssemblyに含まれる)
Assembly asm = Assembly.GetExecutingAssembly();
// DLL名は指定しないパターンでの例外処理
Type t = asm.GetType(className);
if (t == null)
{
throw new BusinessSystemException("NoLBTypeInExecutingAssembly", string.Format("{0}クラスがExecutingAssemblyに存在しません。", className));
}
object o = Activator.CreateInstance(t);
muReturnValue = (MuReturnValue)Latebind.InvokeMethod(o, FxLiteral.TRANSMISSION_INPROCESS_METHOD_NAME, paramSet);
}
catch (System.Reflection.TargetInvocationException rtEx)
{
// InnerExceptionを投げなおす。
throw rtEx.InnerException;
}
#endregion
#region 戻り値
// ★
status = FxLiteral.SIF_STATUS_SERIALIZE;
returnValue = muReturnValue.Bean;
if (muReturnValue.ErrorFlag)
{
// エラー情報を設定する。
wsErrorRoot = wsErrorInfo.CreateElement("ErrorInfo");
wsErrorInfo.AppendChild(wsErrorRoot);
// 業務例外
wsErrorItem = wsErrorInfo.CreateElement("ErrorType");
wsErrorItem.InnerText = FxEnum.ErrorType.BusinessApplicationException.ToString();
wsErrorRoot.AppendChild(wsErrorItem);
wsErrorItem = wsErrorInfo.CreateElement("MessageID");
wsErrorItem.InnerText = muReturnValue.ErrorMessageID;
wsErrorRoot.AppendChild(wsErrorItem);
wsErrorItem = wsErrorInfo.CreateElement("Message");
wsErrorItem.InnerText = muReturnValue.ErrorMessage;
wsErrorRoot.AppendChild(wsErrorItem);
wsErrorItem = wsErrorInfo.CreateElement("Information");
wsErrorItem.InnerText = muReturnValue.ErrorInfo;
wsErrorRoot.AppendChild(wsErrorItem);
// ログ出力用の情報を保存
errorType = FxEnum.ErrorType.BusinessApplicationException.ToString(); // 2009/09/15-この行
errorMessageID = muReturnValue.ErrorMessageID;
errorMessage = muReturnValue.ErrorMessage;
errorToString = muReturnValue.ErrorInfo;
// エラー情報を戻す。
return wsErrorInfo.InnerXml;
}
#endregion
// ★
status = "";
// 戻り値を返す。
return "";
}
//catch (BusinessApplicationException baEx)
//{
// ここには来ない↑
//}
catch (BusinessSystemException bsEx)
{
// エラー情報を設定する。
wsErrorRoot = wsErrorInfo.CreateElement("ErrorInfo");
wsErrorInfo.AppendChild(wsErrorRoot);
// システム例外
wsErrorItem = wsErrorInfo.CreateElement("ErrorType");
wsErrorItem.InnerText = FxEnum.ErrorType.BusinessSystemException.ToString();
wsErrorRoot.AppendChild(wsErrorItem);
wsErrorItem = wsErrorInfo.CreateElement("MessageID");
wsErrorItem.InnerText = bsEx.messageID;
wsErrorRoot.AppendChild(wsErrorItem);
wsErrorItem = wsErrorInfo.CreateElement("Message");
wsErrorItem.InnerText = bsEx.Message;
wsErrorRoot.AppendChild(wsErrorItem);
// ログ出力用の情報を保存
errorType = FxEnum.ErrorType.BusinessSystemException.ToString(); // 2009/09/15-この行
errorMessageID = bsEx.messageID;
errorMessage = bsEx.Message;
errorToString = bsEx.ToString();
// エラー情報を戻す。
return wsErrorInfo.InnerXml;
}
catch (FrameworkException fxEx)
{
// エラー情報を設定する。
wsErrorRoot = wsErrorInfo.CreateElement("ErrorInfo");
wsErrorInfo.AppendChild(wsErrorRoot);
// フレームワーク例外
// ★ インナーエクセプション情報は消失
wsErrorItem = wsErrorInfo.CreateElement("ErrorType");
wsErrorItem.InnerText = FxEnum.ErrorType.FrameworkException.ToString();
wsErrorRoot.AppendChild(wsErrorItem);
wsErrorItem = wsErrorInfo.CreateElement("MessageID");
wsErrorItem.InnerText = fxEx.messageID;
wsErrorRoot.AppendChild(wsErrorItem);
wsErrorItem = wsErrorInfo.CreateElement("Message");
wsErrorItem.InnerText = fxEx.Message;
wsErrorRoot.AppendChild(wsErrorItem);
// ログ出力用の情報を保存
errorType = FxEnum.ErrorType.FrameworkException.ToString(); // 2009/09/15-この行
errorMessageID = fxEx.messageID;
errorMessage = fxEx.Message;
errorToString = fxEx.ToString();
// エラー情報を戻す。
return wsErrorInfo.InnerXml;
}
catch (Exception ex)
{
// エラー情報を設定する。
wsErrorRoot = wsErrorInfo.CreateElement("ErrorInfo");
wsErrorInfo.AppendChild(wsErrorRoot);
// フレームワーク例外
// ★ インナーエクセプション情報は消失
wsErrorItem = wsErrorInfo.CreateElement("ErrorType");
wsErrorItem.InnerText = FxEnum.ErrorType.ElseException.ToString();
wsErrorRoot.AppendChild(wsErrorItem);
wsErrorItem = wsErrorInfo.CreateElement("MessageID");
wsErrorItem.InnerText = "-";
wsErrorRoot.AppendChild(wsErrorItem);
wsErrorItem = wsErrorInfo.CreateElement("Message");
wsErrorItem.InnerText = ex.ToString();
wsErrorRoot.AppendChild(wsErrorItem);
// ログ出力用の情報を保存
errorType = FxEnum.ErrorType.ElseException.ToString(); // 2009/09/15-この行
errorMessageID = "-";
errorMessage = ex.Message;
// どちらを戻すべきか?
// Muの場合は、Messageがデフォ
errorToString = ex.Message;
//errorToString = ex.ToString();
// エラー情報を戻す。
return wsErrorInfo.InnerXml;
//throw; // コメントアウト
}
finally
{
// 用途によってSessionを解放するかどうかを検討。
//// Sessionステートレス
//Session.Clear();
//Session.Abandon();
// 終了ログの出力
if (status == "")
{
// 終了ログ出力
LogIF.InfoLog("SERVICE-IF", "正常終了");
}
else
{
// 終了ログ出力
LogIF.ErrorLog("SERVICE-IF",
"異常終了"
+ ":" + status + "\r\n"
+ "エラー タイプ:" + errorType + "\r\n" // 2009/09/15-この行
+ "エラー メッセージID:" + errorMessageID + "\r\n"
+ "エラー メッセージ:" + errorMessage + "\r\n"
+ errorToString + "\r\n");
}
}
}
#endregion
}
}