Original address: Http://msdn.microsoft.com/zh-cn/magazine/cc163482.aspx
Directory
Queued Call
Response Service
Design Response Service Contract
Using Message headers
ResponseContext class
Client programming
Server-side programming
Response Service Programming
Conclusion
Windows Communication Foundation (WCF) enables clients and services to communicate in a connectionless manner. The client publishes the message to the queue, and the service then processes the messages later. This interaction creates a different programming model from the default request/response pattern, which is expected to better balance the load, increase usability, and compensate for the benefits to the user. This column begins with a brief introduction to Windows®communication Foundation's queued invocation capabilities, and then presents an interesting question, "How to get results from queued calls," and then through some cool Windows communication Foundation programming techniques and the helper classes I've written to find a solution.
Queued Call
Windows Communication Foundation uses netmsmqbinding to support queued calls. Windows Communication Foundation transmits messages not through TCP or HTTP, but through Microsoft® Message Queuing (MSMQ). Instead of sending Windows communication Foundation messages to an online service, the client is sent to an MSMQ queue. The objects that all clients face and interact with are queues, not service endpoints. Therefore, the invocation is inherently asynchronous and not connected. These calls are not executed until the service processes messages at some point in the future.
Note that Windows communication Foundation messages do not map directly to MSMQ messages. An MSMQ message can contain one or more Windows communication Foundation messages, depending on the contract session mode. For required session mode, multiple Windows Communication Foundation invocations can coexist in an MSMQ message, and for allow or disallow session mode (used by single invocation and single-instance services), each Windows communication The Foundation call will be in a separate MSMQ message.
As with each Windows communication Foundation service, the client interacts with the agent, as shown in Figure 1. Because the agent is configured to use MSMQ bindings, the agent does not send Windows communication Foundation messages to any particular service, but instead converts the call to an MSMQ message and then publishes the messages to the queue specified by the endpoint address.
Figure 1WCF Queued Call architecture