wcf entry (3) - Request reply mode

This article demo has been uploaded to GitHub: xinyuehtx / WCFdemo

This blog will explain how to set up call service mode of operation


Call a WCF service has three modes: a request reply mode (Request-Repley), the one-way mode (One-Way), duplex mode (Duplex)

Request reply mode

Here Insert Picture Description

Call service request reply mode as shown in the way, this is the default behavior of the service.

Here Insert Picture Description

As shown we have created a service agreement IRequestResponse, and defines the methods SayHelloand they use OperationContractAttributethe default constructor to specify, indicating that this method is a request reply mode.

Then we complete the rest.

Here Insert Picture Description

Here Insert Picture Description
Here Insert Picture Description

This example and the previous HelloWorld no difference.

But careful students have found that where a request reply to the reply mode?

Because our method is voida method, there is no return value.

Now we add another method SayHello2and returns a string

Here Insert Picture Description

Here Insert Picture Description

Here Insert Picture Description

We are now trying to return the output value

Here Insert Picture Description
The results shown in FIG.

Here Insert Picture Description

This time there are a number of small partners carefully found the problem, we call the client service approach is a synchronization method.

Then the server computing and communication delay is bound to cause the client Caton

The default WCF communication time is 1min, we try to add delays in service implementation

Here Insert Picture Description
Here Insert Picture Description

Zaoxin good ~ ~ then the above voidmethod always all right now. We continue to experiment

This time SayHellothe voidadded delay method

Here Insert Picture Description

Failed ++

Here Insert Picture Description

summary

We studied the request reply mode WCF service, its features are

  • simple
  • The return value can be obtained
  • A synchronization method, there is the risk of timeouts

Problem Solution

So for those consuming services, the emergence of a timeout problem how to solve it?

  1. Try using a short service computing function, a large number of mobile computing tasks recommended to the client
  2. No synchronization required for the implementation of the voidmethod, you can try单向模式
  3. For non-synchronized not perform the required voidmethod, you can try异步服务

While 单向模式and 异步服务can be introduced in a later blog post

Reference links:


This article will be updated frequently, please read personal blog Original: https://xinyuehtx.github.io/ , in order to avoid misleading the old error of knowledge, and a better reading experience.

Creative Commons License This work is Creative Commons Attribution - NonCommercial - ShareAlike 4.0 International License Agreement for licensing. Welcome to reprint, use, repost, but be sure to keep the article signed by Huang Tengxiao (containing links: https://xinyuehtx.github.io/ ), shall not be used for commercial purposes, be sure to publish the same work based on the paper license modification. If you have any questions, please contact me .

Published 54 original articles · won praise 0 · Views 2436

Guess you like

Origin blog.csdn.net/htxhtx123/article/details/104206148