WCF サービスを使用したクライアント サーバー アプリケーションがあり、COM インターフェイスとして提示された ComObject をクライアントからサーバーに何らかの状態で送信する必要があります。ComObject はシリアル化できないため、サーバー側で新しいインスタンスを作成し、正しい状態を復元する必要があります。
クライアント側で ComObject のこの状態を取得し、サーバー側でインターフェイス実装インスタンスを作成するにはどうすればよいですか?
ComObject の定義:
public class SyncSessionContext
{
...
private CoreInterop.ISyncSessionState rawState;
...
}
COM インターフェイスの定義
internal static class CoreInterop
{
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("b8a940fe-9f01-483b-9434-c37d361225d9")]
[ComImport]
public interface ISyncSessionState
{
[MethodImpl(MethodImplOptions.InternalCall | MethodImplOptions.PreserveSig, MethodCodeType = MethodCodeType.Runtime)]
int GetInfoForChangeApplication([MarshalAs(UnmanagedType.LPArray), In, Out] byte[] ppbChangeApplierInfo, [In, Out] ref uint pcbChangeApplierInfo);
...other methods
}
}
私のクライアント側のコード:
public override void BeginSession(SyncProviderPosition position, SyncSessionContext syncSessionContext)
{
var field = typeof(SyncSessionContext).GetField("rawState", BindingFlags.Instance | BindingFlags.NonPublic);
// Nonserializable correct instance
var rawState = field.GetValue(syncSessionContext);
//extract state...
var state = ?????
//calling wcf service
proxy.BeginSession(position, state);
}
私のサーバー側のコード:
public void BeginSession(SyncProviderPosition position, object state)
{
//initializing and restoring state
var rawState = ?????
syncSessionContext = new SyncSessionContext(IdFormats(), null);
var field = typeof(SyncSessionContext).GetField("rawState", BindingFlags.Instance | BindingFlags.NonPublic);
field.SetValue(syncSessionContext, rawState);
KnowledgeSyncProvider.BeginSession(position, syncSessionContext);
}