Multithread programming learning notes-asynchronous calling of the WCF Service and multi-threaded programming of the wcf

Source: Internet
Author: User

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.

 

 

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.