Let's take a look at the fourth article about single communication and two-way communication in WCF, and the fourth article about communication in wcf.

Source: Internet
Author: User

Let's take a look at the fourth article about single communication and two-way communication in WCF, and the fourth article about communication in wcf.

For personal reasons, I have not updated this series for a long time. I will continue to update this series of articles. This chapter provides one-way and two-way communication. The so-called one-way Mode means that only sending but not replying, both sending and replying are supported. There is always one way, and the exchange of gifts represents two ways. Below I will use a simple example (one of the teachers accepts the harsh words, and the other is the opposite)


First, let's look at one-way communication:

Step 1: Write a service agreement

1 [ServiceContract (Namespace = "singleTrans")] 2 public interface ITeacher3 {4 [OperationContract (IsOneWay = true)] 5 void Speak (string message); 6}One-way service agreement

Note 1: IsOneWay = true indicates one-way communication, and false indicates two-way communication.

Step 2: complete the service agreement

1 public void Speak (string message) 2 {3 Console. WriteLine ("command issued by the Instructor: {0}", message); 4}Implementation Agreement

Step 3: Configure the server (same as previous articles)

Step 4: client call results

Then one-way communication is complete.

Now let's modify the service agreement.

Protocol [ServiceContract (Namespace = "singleTrans")] public interface ITeacher {[OperationContract (IsOneWay = true)] string Speak (string message);} implement public string Speak (string message) {Console. writeLine ("commands issued by the Instructor: {0}", message); return "ensure task completion ";}Modified Version

Running result:

Summary of all errors:

One-way communication is enabled. No return value (void is acceptable) or out parameter is allowed.

Now let's look at the two-way agreement.

Set IsOneWay to false. Then, run the following command to check the result.

This operation succeeds. Both the service and the returned data are called.

This article is also quite simple, but a lot of deeper things need to be understood by yourself.

Source code download

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.