Difference between HTTP and Tcp Duplex Communication

Source: Internet
Author: User


In WCF, HTTP and Tcp Protocols are often used for duplex communication. The corresponding protocols are WsDualHttpBinding and NetTcpBinding.
HTTP is based on the application layer protocol, while Tcp is based on the transport layer protocol. Tcp uses three handshakes to establish a reliable connection between the client and the server. Both the client initiating the request and the server of the callback client can use one connection. When HTTP is used, the connection is closed after a request is sent from the client to the server and the server returns a reply to the client.
Due to the non-connectivity of HTTP, the duplex Based on WsDualHttpBinding may be slightly different from NetTcpBinding when the server calls back the client.
1. NetTcpBinding implements duplex www.2cto.com 1.1 Contract Section: 1.1.1 contract interface Definition: [ServiceContract (CallbackContract = typeof (ICallback)] public interface ICalculator {[OperationContract] void Add (double x, double y);} 1.1.2 callback interface Definition: public interface ICallback {[OperationContract] void Display (double x, double y, double result);} 1.2 service implementation: public void Add (double x, double y) {Console. writeLine ("START Add Calculation"); ICallback callbac K = OperationContext. current. getCallbackChannel <ICallback> (); callback. display (x, y, x + y); Console. writeLine (string. format ("{0}, {1}", x, y);} The Service uses OperationContext. current. getCallbackChannel <T> generic method to obtain the callback proxy class for the client, and calls back the public T GetCallbackChannel <T> () {if (this. channel! = Null )&&! This. isUserContext) {return (T) this. channel. proxy;} return default (T); www.2cto.com} 1.3 server configuration: <system. serviceModel> <services> <service name = "Services. calculatorServices "> <endpoint address =" Calaulator "binding =" netTcpBinding "contract =" Contract. ICalculator "> </endpoint>
Client:
2. WsDualHttpBinding implements duplex. Operating System: XP SP3. IIS Version: Take the same contract as above 5.1 as an example. In the packet or request-response mode, if you change the protocol, you only need to change the binding used. We changed the client configuration to the following: <system. serviceModel> <client> <endpoint address = "http: // 127.0.0.1: 8866/Calaulator/ws" binding = "wsDualHttpBinding" contract = "Contract. ICalculator "name =" calculatorWsDual "> </endpoint> </client> </system. serviceModel> then use calculatorWsDual to regenerate ChannelFactory: using:

The solution is to configure the binding behavior for the Endpoint as follows: <system. serviceModel> <bindings> <wsDualHttpBinding> <binding name = "myWsDualBinding" clientBaseAddress = "http: // 127.0.0.1: 3636/Service/CallbackService "> </binding> </wsDualHttpBinding> </bindings> <client> <endpoint address =" http: // 127.0.0.1: 8888/Service/Calculator "binding =" wsDualHttpBinding "contract =" Contracts. ICalculator "name =" calculatorService "bindingConfiguration =" myWsDualBinding "/> </client> </system. serviceModel> in this way, the problem is solved by the author tyb1222.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.