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
Call service request reply mode as shown in the way, this is the default behavior of the service.
As shown we have created a service agreement IRequestResponse
, and defines the methods SayHello
and they use OperationContractAttribute
the default constructor to specify, indicating that this method is a request reply mode.
Then we complete the rest.
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 void
a method, there is no return value.
Now we add another method SayHello2
and returns a string
We are now trying to return the output value
The results shown in FIG.
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
Zaoxin good ~ ~ then the above void
method always all right now. We continue to experiment
This time SayHello
the void
added delay method
Failed ++
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?
- Try using a short service computing function, a large number of mobile computing tasks recommended to the client
- No synchronization required for the implementation of the
void
method, you can try单向模式
- For non-synchronized not perform the required
void
method, 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.
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 .