Multithread programming learning notes-asynchronous calling of the WCF Service and multi-threaded programming of the wcf
Multi-thread programming learning notes-use Asynchronous IO
Multi-thread programming learning notes-write an asynchronous HTTP server and client
Multi-thread programming learning notes-asynchronous database operations
This example describes how to create a WCF Service and host it in a command line application. The client can access the service metadata and consume it asynchronously.
First, we created a WCF Service. For details about how to create a WCF Service, refer to my previous article (a journey to WCF learning-one of the third example () to the fifth () of the third example ))
Then, we generate the proxy code that calls WCF asynchronously.
Third, in the resource manager of visual studio, right-click and select "add service reference..." in the pop-up menu ...". For example.
4. On the "add service reference" Page, after selecting the service to be added, click the "advanced" button and select "generate Asynchronous Operation" in "service reference Settings ", click "OK ". For example.
Fifth, in Solution Explorer, select the "FrmBook. cs" file, right-click it in the pop-up menu, or double-click it with the left mouse button.
6. On the FrmBook. cs page, add the "select books for asynchronous query" button and double-click the button.
7. Add the following code in the buttonAsyncGetBook_Click event handler:
/// <Summary> /// asynchronously query book information /// </summary> /// <param name = "sender"> </param> // <param name = "e"> </param> private void buttonAsyncGetBook_Click (object sender, eventArgs e) {Books book = new Books (); var client = GetAsyncBook (book); // client. getAwaiter (). getResult (); // ShowBook ();} private async Task GetAsyncBook (Books book) {BookServiceRef. bookServiceClient bookSvrClient = new BookServiceRef. book ServiceClient (); if (gridBooks. selectedRows. count> 0) {book = gridBooks. selectedRows [0]. dataBoundItem as Books; textBoxMsg. text = book. bookID. toString (); await Task. delay( 200); var result = bookSvrClient. getBookAsync (book. bookID. toString (); textBoxMsg. text = result. result;} else {textBoxMsg. text = "no corresponding record is selected! ";}}
Eighth, after calling the service of WCF asynchronously, the result is as follows. My journey to learning from WCF-the third sample series is slightly different.