enzom83
enzom83

Reputation: 8310

Duplex service with callbacks

Suppose we have a service with the following methods.

[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(ISampleServiceCallback))]
interface ISampleService
{
    [OperationContract(IsOneWay = true, IsInitiating = true, IsTerminating = false)]
    void Connect(string version);

    [OperationContract(IsOneWay = true, IsInitiating = false, IsTerminating = false)]
    void Request(string uuid, string description);

    [OperationContract(IsOneWay = true, IsInitiating = false, IsTerminating = true)]
    void Disconnect();
}

interface ISampleServiceCallback
{
    [OperationContract(IsOneWay = true)]
    void Reply(string uuid, string description);
}

The client calls the Connect method and a new session starts between client and server. During this session, the client may call the Request method... The server, after receiving the request message, if it is able to respond to the client, it sends a reply using the callback.

Suppose now that the two nodes are not a client and a server, but they are the two peers. How can I make two-way communication? I wish that each of the two nodes can call the Request of the other node ... Is it possible? In other words, one of the two nodes decide to create a new session with another node by calling the Connect method of the other node ... if the latter accepts the connection, a new communication session is created, but both nodes must be able to call methods of the other node.

My idea was to create two sessions between the two nodes: in the first session the node A is the client, while node B is the server; the second session has the opposite direction: the node B is the client, while node A is the server. However, in this way I have two TCP connections ... Are there any alternatives?

Here is a chart that explains how it should work: http://imageshack.us/photo/my-images/600/multipleservices.png/

Thanks a lot!

Upvotes: 2

Views: 360

Answers (2)

slfan
slfan

Reputation: 9129

What you want is duplex communication, right? It depends on the binding, wether it is possible or not. You could use WsDualHttpBinding, but that is not recommended because it is not an official standard. Most of the Tcp Bindings support duplex. You find information here or on this post.

Upvotes: 1

RobertMS
RobertMS

Reputation: 1155

Have you investigated the NetPeerTcpBinding binding? You can also use some kind of peer resolver and I think WCF will use PNRP (Peer Name Resolution Protocol - from Microsoft) by default. Or, if you are feeling adventurous, you can implement you own peer resolver.

Upvotes: 1

Related Questions