Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Information Exchange Mode of WCF Datagram

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to realize the information exchange mode of WCF Datagram". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Of all the WCF services, some use a very typical communication mode. The communication pattern referenced in the WCF document is the message exchange pattern, but "Shape" is also described as the interface type of our implementation pattern. An overview of WCF Learning Notes examples, here are three message exchange modes:

1. Datagram mode, or single-line mode. In this mode, the data flow is transmitted only from the client to the server.

two。 Request response mode, in which the data flow goes from the client to the server, and then the server sends the response information back to the client.

3. Datagram and request response mode, which has the characteristics of both modes.

Because Datagram mode is a basic mode, and it is very easy to implement. Therefore, the example in this article will be implemented in Datagram mode. In this example, there are three channels in the channel stack. One is the transport channel, which is responsible for creating and transmitting messages, and the other two are protocol channels, which are responsible for attaching the message header to the message data. The state machine that manages WCF communication can invoke the functionality of the channel asynchronously or synchronously. Each message exchange pattern contains each call type. For simplicity, only synchronization is used here. There is also this example that interacts directly with the channel stack. Therefore, the contract is not declared in the example code. In order to run the example program, we need a SDK of * *.

As can be seen from the above, this example implements the Datagram information exchange mode. Therefore, the channel needs to implement the IInputChannel interface. The example summary code of WCF Learning Notes is as follows:

Class TestTransportChannel: ChannelBase,IInputChannel {protected EndpointAddress localAddress; public TestTransportChannel (TestTransportChannelListener parent, EndpointAddress address): base (parent) {. This.localAddress = address;}

There are two key methods in IInputChannel, the WaitForMessage and Receive methods. When a message appears, WaitForMessage returns true. Then Receive got the news. The following code receives messages using one of the protocol stacks:

Public Message Receive (TimeSpan timeout) {Message msg; MessageHeader mh; BigHelper.DisplayMessage ("Receive" + this.ToString ()); msg = ((TestLevel2ChannelListener) this.Manager) .GetMessage (timeout); mh = MessageHeader.CreateHeader ("Level2", "this.ToString" 2 "); msg.Headers.Add (mh); return msg;}

The Receive method returns a Message object. The Message object is passed to the various layers of the WCF. Next, let's look at the implementation of ChannelListener.

This is the end of the content of "how to realize the information exchange mode of WCF Datagram". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report