I have an idea, but I need help in its implementation.
WCF does not support delegates in their contracts. Instead, it has a cumbersome callback contract mechanism, and I'm looking for a way to overcome this limitation.
I thought about using IDataContractSurrogateto replace each delegate in the contract with a marker, which will be serialized for the remote endpoint. There, the token will be deserialized into the generated delegate. This generated delegate will send a generic callback message that encapsulates all the arguments (with which the delegate was called).
The general callback message will reach the first endpoint, and there the original delegate will be called with arguments.
Here is the assigned (simplified) sequence:
- A calls B-proxy.Foo (callback)
- the callback is serialized through the Surrogate delegate.
- The delegate Surrogate stores the delegate in a dedicated delegate store and replaces it with a token
- The message reaches end point B
- the token is deserialized through DelegateSurrogate
- Delegate Surrogate creates a generated delegate
- B.Foo call is invoked (generated by Callback)
- B later calls generateCallback (args)
- createdCallback (args) calls the highlighted shared contract for the endpoint: CallbackContract-proxy.GenericCallback (args)
- CallbackContract.GenericCallback (args) called at endpoint A
- The original callback is retrieved from the repository and called: callback (args)
(NServiceBus), WCF, . , 3,6,9 11. , WCF - .
- , , .
:
remoteSvc.GetEmployeeById(17, emp =>
{
employees.Add(emp);
logger.log("Result received");
});
public void GetEmployeeById(int id, Action<Employee> callback)
{
var emp = getEmpFromDb(id);
callback(emp);
}