1

I'm a WCF newbie, and I need some help to begin with a project:

I will have a managed application (server) that needs to communicate (messaging system) with several clients over the internet and vice versa.

What is the best approach to achieve this? using wsDualBinding?

UPDATE

I decided to use the NetTcpBinding mode instead.

Eduardo Brites
  • 4,597
  • 5
  • 36
  • 51

2 Answers2

3

It depends on what capabilities your service needs to expose, and what type of clients you need to support. Any of the HTTP-based bindings will work over the internet, its simply a question of the way the data is encoded.

A summary of the built-in bindings and what they support can be found here: http://msdn.microsoft.com/en-us/library/ms731092.aspx

But the most common are:

  • BasicHttpBinding - This is a basic web service-style binding, usable by any SOAP client.
  • WebHttpBinding - This allows your service to be used by non-SOAP HTTP clients
  • WsHttpBinding - This allows your service to use extended service features like transactions and sessions.
  • WsDualHttpBinding - This is required if your service needs a duplex channel, meaning your service needs to make callbacks up to the client.

Since you specifically asked about the dual binding:

If you are writing an application that needs to be able to make a callback from server into the client, then a dual binding is really your only option. Since you specifically mentioned chat, however, I don't think a dual-channel service is going to work very well.

The way the callbacks work in WCF is that your client makes a call to the service, using a dual channel, and must provide an implementation of the callback interface. The server can use this to make calls to the client for the duration of the service method call; the callback context is per-service-call, so once that call returns, it is no longer valid. In other words, your server cannot just asynchronously "call into" your client, it has to wait for the client to "poll" the server. And if you're going to do that, you don't really need the callback anymore.

Honestly, I don't think I would use WCF for an interactive bi-directional chat application, but I can think of two possible options to do so:

  1. Do the polling client option, using a simple BasicHttpBinding on the server and continuously ask for new messages.
  2. Set your client applications up to self-host a local WCF service, and provide the endpoint information to the server when you log in. This requires your clients to accept incoming connections, which gets messy (but if you can pull it off, I'd go for a NetTcpBinding here.)
Michael Edenfield
  • 28,070
  • 4
  • 86
  • 117
  • I'm aware of the possible options, my question is to know if the wsdualhhtpbinding is the best solution for a "chat" system. Both the server app and the client apps are built in WPF. – Eduardo Brites Jun 03 '12 at 14:51
1

WSDualHttpBinding is not a good choice for internet. Callback works great only in local network (intranet) that has no Firewall and NAS restrictions.

See this post for more details:

Connecting over internet to WCF service using wsDualHttpBinding times out

Use WsHttpBinding if you want to set up server to server communications (that should work for WPF).

Use WebHttpBinding if you are planning to use data from Javascript.

Community
  • 1
  • 1
Dmitry Harnitski
  • 5,838
  • 1
  • 28
  • 43