Say I have WCF service contract like this
[ServiceContract(CallbackContract = typeof(ICallback1),
SessionMode = SessionMode.Required)]
public interface IService1
{
// some methods
}
The service implementation has InstanceContextMode.Single
set for InstanceContextMode
and ICallback1
is something like
public interface ICallback1
{
[OperationContract]
void Report(int someValue);
}
Now on client side, I can have a class the implements ICallback1 like
class Callback1 : ICallback1
{
public void Report(int someValue)
{
// alert client
}
}
and I create client service reference like this
Service1Client serviceClient = new Service1Client(new InstanceContext(new CallBack1()));
which works fine. Now the problem is that I have some clients that are not interested in the callback so I figured I do not require to implement the callback interface for such clients so I tried this
Service1Client serviceClient = new Service1Client(null);
and
Service1Client serviceClient = new Service1Client(new InstanceContext(null));
both reported that the parameter cannot be null
. My question is, how can i create a service reference without passing a callback object if the client is not interested in the callback. The only requirement is that all clients should be talking to the same service but otherwise I can restructure the service however. Any thoughts ?
EDIT:
I have also tried SessionMode = SessionMode.Allowed
for ServiceContract instead of SessionMode.Required
but that didn't help either.
This is the WsDualHttpBinding. This binding is designed for use with Duplex Service contracts, which allows both the Services and clients to send and receive the messages.
A duplex service contract is a message exchange pattern in which both endpoints can send messages to the other independently. A duplex service, therefore, can send messages back to the client endpoint, providing event-like behavior.
Abstract: In WCF, callback is used to implement PUSH mechanism, so that delayed or long running operation results can be automatically pushed back to the client application. WCF actively supports callback to its client, over the instance context established. In this article, we will explore the same.
Callback contracts that have one-way operations represent calls from the service that the client can handle. Note. The ServiceContractAttribute attribute is ignored on callback contracts. To configure runtime behavior of callback objects, use the System. ServiceModel.
Workaround: Remove the CallbackContract from IService1. Create IDuplexService1 which inherits IService1 and contains the CallbackContract. Have Service1Client implement IDuplexService1. When instantiating the host, call ServiceHost.AddServiceEndpoint
for both IService1 and IDuplexService1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With