質問編集履歴
1
"試行内容"を追加致しました。ご確認よろしくお願い致します。
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,6 +7,10 @@
|
|
7
7
|
|
8
8
|
※イメージ
|
9
9
|

|
10
|
+
|
11
|
+
### 進捗状況
|
12
|
+
Form1,Form2の画面の表示(インスタンスの生成)は出来ています。
|
13
|
+
|
10
14
|
### ソースコード
|
11
15
|
※フォーム1はC#、フォーム2はVBで開発しています。
|
12
16
|
|
@@ -15,9 +19,6 @@
|
|
15
19
|
<Window x:Class="Form1.MainWindow"
|
16
20
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
17
21
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
18
|
-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
19
|
-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
20
|
-
mc:Ignorable="d"
|
21
22
|
Title="MainWindow" Height="450" Width="800">
|
22
23
|
<Grid>
|
23
24
|
<TextBox x:Name="TextBox1" HorizontalAlignment="Left" Height="23" Margin="61,40,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
|
@@ -28,10 +29,6 @@
|
|
28
29
|
|
29
30
|
②フォーム1のコードビハインドクラス
|
30
31
|
```
|
31
|
-
using System.Diagnostics;
|
32
|
-
using System.ServiceModel;
|
33
|
-
using System.Windows;
|
34
|
-
|
35
32
|
namespace Form1
|
36
33
|
{
|
37
34
|
/// <summary>
|
@@ -55,20 +52,13 @@
|
|
55
52
|
/// <summary>
|
56
53
|
/// ボタン押下時のイベント
|
57
54
|
/// </summary>
|
58
|
-
/// <param name="sender"></param>
|
59
|
-
/// <param name="e"></param>
|
60
55
|
private void Button_Click(object sender, RoutedEventArgs e)
|
61
56
|
{
|
62
57
|
try
|
63
58
|
{
|
64
59
|
var message = Host.CallExecute(TextBox1.Text);
|
65
|
-
|
66
60
|
MessageBox.Show(message);
|
67
61
|
}
|
68
|
-
catch(ProtocolException ex)
|
69
|
-
{
|
70
|
-
MessageBox.Show(ex.Message);
|
71
|
-
}
|
72
62
|
catch(FaultException<FailureInfo> fx)
|
73
63
|
{
|
74
64
|
FailureInfo info = fx.Detail;
|
@@ -82,8 +72,6 @@
|
|
82
72
|
|
83
73
|
③サービスのインタフェース
|
84
74
|
```
|
85
|
-
using System.ServiceModel;
|
86
|
-
|
87
75
|
namespace Form1
|
88
76
|
{
|
89
77
|
[ServiceContract]
|
@@ -98,10 +86,6 @@
|
|
98
86
|
|
99
87
|
④サービスの具象クラス
|
100
88
|
```
|
101
|
-
using System;
|
102
|
-
using System.Reflection;
|
103
|
-
using System.ServiceModel;
|
104
|
-
|
105
89
|
namespace Form1
|
106
90
|
{
|
107
91
|
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
|
@@ -118,8 +102,6 @@
|
|
118
102
|
|
119
103
|
⑤デバッグ用(FaultExceptionでプロセス間通信の例外を見るために使用)
|
120
104
|
```
|
121
|
-
using System.Runtime.Serialization;
|
122
|
-
|
123
105
|
namespace Form1
|
124
106
|
{
|
125
107
|
[DataContract]
|
@@ -134,38 +116,15 @@
|
|
134
116
|
}
|
135
117
|
```
|
136
118
|
|
137
|
-
⑥フォーム2の
|
119
|
+
⑥フォーム2のコードビハインドクラス
|
138
120
|
```
|
139
|
-
<Window x:Class="MainWindow"
|
140
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
141
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
142
|
-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
143
|
-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
144
|
-
mc:Ignorable="d"
|
145
|
-
Title="MainWindow" Height="450" Width="800">
|
146
|
-
<Grid>
|
147
|
-
<TextBox x:Name="TextBox1" HorizontalAlignment="Left" Height="23" Margin="50,33,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
|
148
|
-
</Grid>
|
149
|
-
</Window>
|
150
|
-
```
|
151
|
-
|
152
|
-
⑦フォーム2のコードビハインドクラス
|
153
|
-
```
|
154
|
-
Imports System.ServiceModel
|
155
|
-
Imports Form1
|
156
|
-
|
157
121
|
''' <summary>
|
158
122
|
''' Form2のコードビハインド
|
159
123
|
''' </summary>
|
160
124
|
Public Class MainWindow
|
161
|
-
|
162
125
|
Public Host As ServiceHost
|
163
|
-
|
164
126
|
Public Const Uri As String = "net.pipe://localhost/Form2"
|
165
127
|
|
166
|
-
''' <summary>
|
167
|
-
''' コンストラクタ
|
168
|
-
''' </summary>
|
169
128
|
Public Sub New()
|
170
129
|
Host = New ServiceHost(GetType(WcfClient))
|
171
130
|
Host.AddServiceEndpoint(
|
@@ -180,19 +139,98 @@
|
|
180
139
|
''' <summary>
|
181
140
|
''' テキストボックスに値をセットする
|
182
141
|
''' </summary>
|
183
|
-
''' <param name="text"></param>
|
184
|
-
''' <returns></returns>
|
185
142
|
Public Function Reply(ByVal text As String) As String
|
186
143
|
// テキストボックスにフォーム1より受け取った値をセット
|
187
144
|
TextBox1.Text = text
|
188
|
-
|
189
145
|
Return "Form2 Replyメソッドが呼ばれました"
|
190
146
|
End Function
|
191
147
|
End Class
|
192
148
|
```
|
193
149
|
|
194
|
-
###
|
195
|
-
|
150
|
+
### 試行内容
|
151
|
+
「④サービスの具象クラス」を以下のようにFacadeを用い、呼び出すアセンブリ・クラス・メソッドを動的に指定出来るように書き替え、Form1からForm2へプロセス間通信を実行しました。
|
152
|
+
```
|
153
|
+
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
|
154
|
+
public class WcfClient: IWcfClient
|
155
|
+
{
|
156
|
+
public string CallExecute(string text)
|
157
|
+
{
|
158
|
+
// Facadeを用いてForm2のReplyメソッドをコール
|
159
|
+
return Facade<string>("Form2.exe", "Form2.MainWindow", "Reply", text);
|
160
|
+
}
|
161
|
+
private T Facade<T>(string assembly, string className, string methodName, string text = "")
|
162
|
+
{
|
163
|
+
string path = Environment.CurrentDirectory + @"\" + assembly;
|
164
|
+
Assembly asm = Assembly.LoadFrom(path);
|
165
|
+
object obj = asm.CreateInstance(className);
|
166
|
+
Type type = obj.GetType();
|
167
|
+
MethodInfo mi = type.GetMethod(methodName);
|
168
|
+
object[] param = new object[1];
|
169
|
+
param[0] = text;
|
170
|
+
object returnObj = mi.Invoke(obj, param);
|
171
|
+
return (T)returnObj;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
}
|
175
|
+
```
|
176
|
+
上記を実行した結果、以下のスタックトレースが出力されました。
|
177
|
+
```
|
178
|
+
System.ServiceModel.FaultException
|
179
|
+
HResult=0x80131501
|
180
|
+
Message=内部エラーのため、クライアントは要求を処理できませんでした。このエラーの詳細については、例外情報をクライアントに返信するためにサーバーで IncludeExceptionDetailInFaults を有効にするか (ServiceBehaviorAttribute または <serviceDebug> 構成動作を通じて)、Microsoft .NET Framework SDK ドキュメントに従ってトレースを有効にして、サーバーのトレース ログを調べてください。
|
181
|
+
Source=mscorlib
|
182
|
+
スタック トレース:
|
183
|
+
場所 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
|
184
|
+
場所 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
|
185
|
+
場所 Form1.IWcfClient.CallExecute(String text)
|
186
|
+
場所 Form1.MainWindow.Button_Click(Object sender, RoutedEventArgs e) (C:\workspace\20191020\WcfConnection\Form1\MainWindow.xaml.cs):行 34
|
187
|
+
場所 System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
|
188
|
+
場所 System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
|
189
|
+
場所 System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
|
190
|
+
場所 System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
|
191
|
+
場所 System.Windows.Controls.Primitives.ButtonBase.OnClick()
|
192
|
+
場所 System.Windows.Controls.Button.OnClick()
|
193
|
+
場所 System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
|
194
|
+
場所 System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
|
195
|
+
場所 System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
|
196
|
+
場所 System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
|
197
|
+
場所 System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
|
198
|
+
場所 System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
|
199
|
+
場所 System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
|
200
|
+
場所 System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
|
201
|
+
場所 System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
|
202
|
+
場所 System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
|
203
|
+
場所 System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
|
204
|
+
場所 System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
|
205
|
+
場所 System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
|
206
|
+
場所 System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
|
207
|
+
場所 System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
|
208
|
+
場所 System.Windows.Input.InputManager.ProcessStagingArea()
|
209
|
+
場所 System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
|
210
|
+
場所 System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
|
211
|
+
場所 System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
|
212
|
+
場所 System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
|
213
|
+
場所 System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
|
214
|
+
場所 MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
|
215
|
+
場所 MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
|
216
|
+
場所 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
|
217
|
+
場所 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
|
218
|
+
場所 System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
|
219
|
+
場所 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
|
220
|
+
場所 MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
|
221
|
+
場所 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
|
222
|
+
場所 System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
|
223
|
+
場所 System.Windows.Application.RunDispatcher(Object ignore)
|
224
|
+
場所 System.Windows.Application.RunInternal(Window window)
|
225
|
+
場所 System.Windows.Application.Run(Window window)
|
226
|
+
場所 System.Windows.Application.Run()
|
227
|
+
場所 Form1.App.Main()
|
228
|
+
```
|
229
|
+
調べたところ、FaultExceptionの実行例外の詳細をクライアント側で取得するためには⑤のようなデバッグ追跡用のデータクラスが必要であったため、「FailureInfoクラス」を新規作成しました。
|
230
|
+
そしてプロセス間通信の実行例外(FaultException)のスタックトレースを確認するため「④サービスの具象クラス」のように書き換えました。
|
231
|
+
|
232
|
+
### 質問内容
|
233
|
+
「④サービスの具象クラス」でFaultExceptionをスローし、プロセス間通信の実行例外のスタックトレースを確認した結果、以下が出力されました。
|
196
234
|
自身で調査しましたが、真因が追求出来ていません。解決策をご存知の方いらっしゃいましたらご教授お願い致します。
|
197
235
|
```
|
198
236
|
場所 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
|