I have client-server application with WCF services, and i need to send ComObject, presented as COM interface, in some state from client to server. ComObject isn't serializable, therefore i need create a new instance on server side and restore the correct state.
How can i get this state of ComObject on client-side and create the interface implementation instance on server-side?
definition of ComObject:
public class SyncSessionContext
{
...
private CoreInterop.ISyncSessionState rawState;
...
}
definition of COM interface
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
}
}
My client-side code:
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);
}
My server-side code:
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);
}