Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Bindings - so many! How do I choose one?

We have an R Server (R is a programming language used in statistical analysis) that basically takes a script and a csv file, processes some data and returns results as text.

I need to write a service on the R server so that .net clients (could be .Net Windows Forms, or ASP.Net) can connect to the R server, submit the script and CSV file, and get the results back.

I'm confused by the many different bindings available to me and information on the web seems to be sparse/scattered about what one to choose.

Also, is it best to run the service in IIS, or as a separate "command line" type listener service (the latter seems ugly compared to IIS and I have no idea why anyone would choose to do this if they could run it in IIS)?

like image 436
Calanus Avatar asked Oct 26 '08 09:10

Calanus


People also ask

Which binding should I use if I want to safely allow my WCF service usable across machines?

netNamedPipeBinding. This binding is used to provide secure and reliable Named Pipe based communication between WCF services and WCF client on the same machine. It is the ideal choice for communication between processes on the same machine.

What is WCF binding and how many of them do you know?

WCF binding is a set of binding elements and each element specify, how the service and client will communicates with each other's. Each binding must have at least one transport element and one message encoding element.

What are different bindings supported by WCF?

TCP binding It encodes the message in binary format. This is a faster and more reliable binding compared to the HTTP protocol bindings. It is only used when the communication is WCF-to-WCF which means both client and service should have WCF.

What is default binding in WCF?

Default binding WCF allows you to use a default binding that affects all endpoints of all services of the application that uses the config file. A default binding is simply a nameless binding section. For example, in the case of TCP: <netTcpBinding> <binding transactionFlow = "true" /> </netTcpBinding>


2 Answers

Personally, I'd recommend the simplest binding that gives what you need. I've done quite a lot of WCF (some quite complex), and I've never had to use anything other than BasicHttpBinding; this also allows that greatest possible compatibility with non-.NET clients, and lets you use things like MTOM for efficient binary transfer.

Re hosting; IIS is indeed the simplest for a client/server setup; two particular strengths:

  • easy to configure SSL (i.e. you just configure IIS, and WCF will use it)
  • easy to load balance (just load balance your web farm)

(I believe WCF running over BasicHttpProfile can also leverage your IIS compression [GZip/Deflate] setup, but don't quote me...)

You might choose to use a standalone host (usually via a windows service) if (for example) you want a long-running stateful server. IIS has this habit (by design) of recycling the app-pools, which isn't good if you were keeping something in memory! Another example is where you want it to be already running for fast "first hit" performance (rather than waiting for IIS/ASP.NET to spin up). An example covering both of these might be hosting a WF (workflow) server.

Again; if you don't need this complexity, go for the simplest option: hosting in IIS.

like image 86
Marc Gravell Avatar answered Oct 19 '22 16:10

Marc Gravell


Indeed there are many options.

Binding

The bindings available from WCF are a set of protocols for common scenarios. It specifies transport, message and security information.

When choosing a binding, you need to find out what feature you need from it. e.g. you may need a way to

  • authenticate the clients since you do not want everyone is able to use your service.
  • the data might need to be encrypted.
  • the service requires to be interoperable for clients from other platform.
  • the overhead of message is becoming an issue.

If you know the clients are always from dot net, you could utilize net tcp binding, that is faster than basicHttpbinding. However, basicHttpBinding is an interoperable protocol, even php or java clients can talk to it without problem.

Define your own requirements for the service and then look for the existing binding to fit your needs, if there isn't any existing binding, you can create your own binding which is called custom binding, it could combine features from different binding together to achieve the objective.

Hosting

IIS is more scalable. If your service does not require the state which has to be hosted in a long run daemon process(windows service or console app), IIS is the choice since it is easy to enable compression and encrytion for your services.

More on Binding

If you want your service to be called within Browser i.e. javascript WebHttpBinding is good one that dot net defined for you. You can utilize enbableWebScript to make the service understands JSON for javascript.

Availability

If one specific binding can not fulfill all the requirements, you can expose each service in different binding at different endpoints. e.g. host/soap host/nettcp host/json

like image 35
Ray Lu Avatar answered Oct 19 '22 17:10

Ray Lu