Synchronous and asynchronous WCF (using WPF connection as an example), wcfwpf
2016 to 06-0711: 05: 44
When learning about WCF, I learned how to synchronize and asynchronously use the WCF Service.
I understand synchronization as follows:
When the WCF Service is executed synchronously, the program has only one thread, and the code can only be executed step by step in sequence. When the execution of a Client/Server method takes 10 seconds, the code can only be executed after 10 seconds.
When the WCF Service is executed asynchronously, the program can run multiple threads simultaneously. When the client/server executes a method for 10 seconds, the subsequent code is also executed.
1. Create a WCF Service and WPF project. The WPF project references the WCF Service and configure the reference of the WCF Service of the WPF project.
2. Server Interface: ITable1Service
3. Implementation of the server interface: Table1Service
4. Client call. Note: import the server namespace and the WCF Service namespace.
4.1 implement WCF Service Synchronization
Click the "test WCF Service" button to synchronize the execution results of the WCF Service. (The "WCF ended" execution is executed 10 seconds after the "WCF Service synchronization" is executed and the thread is interrupted. Observe the current execution time .)
4.2 asynchronous Implementation of the WCF Service
Click the "test WCF Service" button to asynchronously execute the result of the WCF Service. "WCF Asynchronization" and "WCF termination" are executed at the same time. "WCF termination" does not wait 10 seconds until the "WCF Asynchronization" is executed and then interrupted.
Record completed.