WCF - when should i use netTcpBinding - c#

i usually use HTTP binding at my services.
i read that net.tcp Binding works faster, however i am not quite sure on when should i use it?
what is the best practice,
are there any drawbacks?
thanks

The MSDN page for NetTcpBinding says it best
The default configuration for the NetTcpBinding is faster than the configuration provided by the WSHttpBinding, but it is intended only for WCF-to-WCF communication.
So NetTcpBinding is good to use when you have a .NET WCF client and a .NET WCF server, however if you need to support clients that are not written in .NET WCF (for example you are publishing a public service and you don't know what language the client will be written in) then you need to use a HttpBinding instead.
This page has a good quick summary of each type of binding and when they should be used.
BasicHttpBinding - A binding that is suitable for communicating with WS-Basic Profile conformant Web services, for example, ASP.NET
Web services (ASMX)-based services. This binding uses HTTP as the
transport and text/XML as the default message encoding.
WSHttpBinding - A secure and interoperable binding that is suitable for non-duplex service contracts.
WS2007HttpBinding - A secure and interoperable binding that provides support for the correct versions of the Security,
ReliableSession, and TransactionFlow binding elements.
WSDualHttpBinding - A secure and interoperable binding that is suitable for duplex service contracts or communication through SOAP
intermediaries.
WSFederationHttpBinding - A secure and interoperable binding that supports the WS-Federation protocol, enabling organizations that
are in a federation to efficiently authenticate and authorize users.
WS2007FederationHttpBinding - A secure and interoperable binding that derives from WS2007HttpBinding and supports federated
security.
NetTcpBinding - A secure and optimized binding suitable for cross-machine communication between WCF applications.
NetNamedPipeBinding - A secure, reliable, optimized binding that is suitable for on-machine communication between WCF
applications.
NetMsmqBinding - A queued binding that is suitable for cross-machine communication between WCF applications.
NetPeerTcpBinding - A binding that enables secure, multi-machine communication.
WebHttpBinding - A binding used to configure endpoints for WCF Web services that are exposed through HTTP requests instead of SOAP
messages.
MsmqIntegrationBinding - A binding that is suitable for cross-machine communication between a WCF application and existing
Message Queuing (also known as MSMQ) applications.

Related

Why would anyone like to host WCF using Tcp protocol instead of using a basic Http protocol?

I am new to WCF and I learned that using WCF you can communicate between two or more distributed systems over various protocols and message formats. So far for practice purposes I have used basicHttpBinding. But for demonstration purposes I want to be really convinced where to use netTcpBinding or etc. Please tell me the scenario where net.TcpBinding becomes really useful and almost a must to opt for.
Also as far as I know it is one of the major advantages that WCF offers over it's traditional various counterparts such as ASP .Net Web Services that it can seamlessly communicate over various protocols which other traditional Web Services can't.
Is it true ? Please clarify.
every binding for different goals
Performance is much better with a binary protocol. Serialization is faster and the network is used less.
Also, the NetTcp binding supports more of .NET, for example generics. It is based on BinaryFormatter.
Also see burning_LEGION's diagram, I'm not going to copy it over.
Here are some difference which will help you to understand the answer
BasicHttpBinding - main feature: uses WS-I Basic Profile 1.1 standart mainly used for consuming the old ASMX WebServices. Other important features, you must pay attention on:
Works over http protocol
Supports security according to BasicHttpSecurityElement (None/Transport/Message/TransportWithMessageCredential/TransportCredentialOnly)
Supports message encoding with Mtom (Message Transmission Organization Mechanism 1.0 (MTOM) encoder), used for tranfer of messages with large binary attachments
NetTcpBinding - main feature: uses WS-* standart (has more features then WS-I Basic Profile 1.1) for deploying and consuming of the .NET WCF services in cross-machine communication environment. Other important features:
Works over tcp protocol
Supports security according to NetTcpSecurityElement (None/Transport/Message/Both)
Supports transactions
Supports reliable sessions (can support exactly-once delivery assurances)
Choosing a Transport This link is worth looking at

WCF Routing Service with NetTcpBinding and certificates

We want to add fail over ability to our WCF clients at the client side . The clients are communicating to a WCF service that is implemented over NetTcpBinding with TransportWithMessageCredential security mode and the credential type is certificate.
Is it possible to use .Net 4.0 RoutingService without changing the real service security at all ?
The desired functionality from the router is just to pass the messages from the client to a backup service if the primary service is unavailable.

How can we implement Session management for WebHttpBinding WCF REST Service?

I have been developing a WCF REST service using webHttpBinding Session mode as required.But I am getting this error always "Contract requires Session, but Binding 'WebHttpBinding' doesn't support it or isn't configured properly to support it." Can any one tell what would be the reason for this ?
Quote from the MSDN forums:
You cannot use WebHttpBinding for session based communication as it
doesn't support the concept of sessions. I talked at length about
sessions here -
http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,af6e6325-2e30-42e3-acb9-57e1363fa51e.aspx.
WebHttpBinding doesn't support session for the same reason
BasicHttpBinding doesn't. If you really must have sessions then you
will have to use a binding that supports it. However, PerSession
activation is only one way to maintain per client state. Can you not
use another mechanism, say passing a session id to the service that
you use to wire up your own concept of session?

Which WCF services can you add a service reference to in WP7 Mango?

Just need to know when adding a service reference to a WCF service in a mango silverlight project which types of WCF services (webHttpBinding, WSBinding etc) will visual studio generate a proxy for automatically?
The supported standard bindings are basicHttpBinding - with security mode of either None, Transport or TransportWithMessageCredentials (for username/password over HTTPS), or customBinding. The binding element supported are username/password security, binary/text encodings and http/https transports. You can actually use wsHttpBinding as well, if you disable message security and reliable messaging (it's roughly equivalent to a custom binding with text encoding + http transport).
Ah, and to be able to add a service reference, you'll need to enable metadata on the service (it's the default on the VS templates).

Can we use msmq messaging with wcf data service

I have a Wcf Data service exposing entities from Ado.net entity framework. I would like to know whethere I can use msmq messaging with my data service.
After searching on internet i could find links for using with a wcf service only.
Please provide some links with a sample.
No you cannot.
WCF Data Services is using HTTP/REST only - it cannot be used over any other protocol or with any other binding.
MSMQ is only available when you use "regular" WCF services that use the SOAP protocol for communication - that can be routed over different transport media.
REST is very tightly and intimately tied to HTTP only.
WCF supports MSMQ as a transport protocol and provides the standard MSMQ binding. Here is a link to MSDN article devoted to using MSMQ in a WCF application:
How to: Exchange Messages with WCF Endpoints and Message Queuing Applications

Categories