15 days proficient in WCF-the third communication mode that you must understand on the sixth day, and the sixth day of wcf

Source: Internet
Author: User

15 days proficient in WCF-the third communication mode that you must understand on the sixth day, and the sixth day of wcf

  

I have already talked about the sixth day of wcf, but I haven't said that there are several communication modes. I am ashamed of it, but it's very simple. One-way, request-response, duplex mode, the second type is "request-response".

Mode. You don't need to make it clear. I will give a rough analysis of this Article.

 

I. "request-response" Mode

If you read my previous blog post, you should be very clear about this method similar to "local call". wcf is also divided into "synchronous" and "Asynchronous, however, both asynchronous and synchronous will eventually escape.

It's just the fact of "request-response", right.

 

1: Synchronous Mode

There is nothing to say about this method. I have already explained the previous articles clearly. For details about how to use this method, refer to my previous articles... Thank you ~~~~

 

2: asynchronous mode

We usually have this kind of thinking. When we encounter time-consuming things, we first think of multithreading. After all, multithreading is also a type of load balancing. In the "request-response" mode of wcf, also supports exception

Step, it's amazing, and it's amazing that one-click generation can be performed on the "service reference" interface. What ??? You don't believe it !!!! Don't believe it...

 

Then I am very curious to see what code XXXClient has generated for us...

 

Through the client-side proxy code, you can clearly see that this is really not easy, and we have generated two "Asynchronous Modes", the first is the oldest beginXXX, endXXX mode,

Another is the "event asynchronous mode" that Jeffrey Richter seriously despise "... There is nothing to say. Let's take a look.

 

Ii. "One-Way" Mode

Most of the time, we may all have such a requirement. For example, when the order is successfully submitted, I need to send an email to the customer, but you can think about it. The task of sending an email is only the process of my order.

An "extra task", that is, its failure should not stop my order process, and its logical time should not hinder the total time of my order, right... In this case, my order

In order to achieve the effect of not affecting the total time of the order, my idea is that the client directly throws the message to the channel and processes the message no matter whether the server receives the message or not.

Slow, slow, good, and so on. I'm very happy that these are really a piece of cake for wcf, just a simple "IsOneWay = true" attribute... Awesome

Dead... There is also a one-way, so there is no need to return the value of the contract method, I am right... Hey ~~~

1     [ServiceContract]2     public interface IHomeService3     {4         [OperationContract(IsOneWay = true)]5         void Update(Student message);6     }
 1 namespace MyService 2 { 3     public class HomeService : IHomeService 4     { 5         public void Update(Student message) 6         { 7             Console.WriteLine(message.Name); 8         } 9     }10 11     [DataContract]12     public class Student13     {14         [DataMember]15         public string Name { get; set; }16 17         [DataMember]18         public int Age { get; set; }19     }20 }

To verify whether it is actually unidirectional communication, I can verify it in two ways.

 

1. Does the wsdl contain the output message?

As shown in the following figure, I think you can see clearly that you have never found the familiar "output" message, which indicates that it is actually one-way, because wsdl is the list of web services.

  

 

2. Use fillder to monitor request messages

1     class Program2     {3         static void Main(string[] args)4         {5             HomeServiceClient client = new HomeServiceClient();6 7             client.Update(new Student() { Name = "hxc" });8         }9     }

  

As I mentioned in the figure, it is very strange that my IsOneWay mode does not work in http mode, but remember that http mode is inherently a "request-response" mode, it cannot do anything at all

One-way mode: "When wcf finds that your bingding does not support one-way", it will not report an error, you can use your own "request-corresponding" mode to simulate "one-way communication ".

The very strange Http 202 status code. Many people, including me, do not know what http202 means. It doesn't matter. Let's just look at it in our encyclopedia... The words in the box below,

I have already made it very clear. Thank you...

 

Iii. Bidirectional Mode

In fact, this communication is not easy to talk about, and only the tcp mode will be supported by nature, but the http mode is not supported by nature. Just like above, if you have to use http to support "two-way communication", that is again in

This will force his father to establish a "request-response" mode at the underlying layer to support the so-called "two-way communication". in addition, "two-way communication" is not as good as two one-way "request-response" models.

Or two "one-way" modes to support, and two "request-response" modes are more flexible than "two-way communication". Anyway, I don't catch a cold on it, if you are interested, you can

Go to the wcf website and check out https://msdn.microsoft.com/zh-cn/library/ms735119.aspx.

 

Well, let's talk about it here. It's good night ~~~~

 

Related Article

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.