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