简体   繁体   English

WCF路由器:一种方法和请求-答复操作

[英]WCF Router: one way and request-reply operations

In order to prepare my 70-513 exam, I found this questions: 为了准备我的70-513考试,我发现了以下问题:

A Windows Communication Foundation (WCF) service implements a contract with one-way and request-reply operations. Windows Communication Foundation(WCF)服务使用单向和请求-答复操作实现合同。 The service is exposed over a TCP Transport. 该服务通过TCP传输公开。 Clients use a router to communicate with the service. 客户端使用路由器与服务进行通信。 The router is implemented as follows. 路由器的实现如下。 (Line numbers are include for reference only.) (包括行号仅供参考。)

01 ServiceHost host = new ServiceHost(typeof(RoutingService));
02 host.AddServiceEndpoint (
03     typeof(ISimplexDatagramRouter),
04     new NetTcpBinding(), "net.tcp://localhost/Router"
05    );
06 List<ServiceEndpoint> lep = new List<ServiceEndpoint>();
07 lep.Add (
08     new ServiceEndpoint (
09         ContractDescription.GetContract(
10             typeof(ISimplexDatagramRouter)
11    ),
12     new NetTcpBinding(),
13     new EndpointAddress("net.tcp://localhost:8080/Logger")
14    )
15 );
16 RoutingConfiguration rc = new RoutingConfiguration();
17 rc.FilterTable.Add(new MatchAllMessageFilter(), lep);
18 host.Description.Behaviors.Add(new RoutingBehavior(rc));

Request-reply operation are failing. 请求答复操作失败。 You need to ensure that the router can handle one-way and request-reply operations. 您需要确保路由器可以处理单向和请求-答复操作。 What should you do? 你该怎么办?

  • A . A. Change line 03 as follows 如下更改03行

    typeof((IRequestReplyRouter) typeof((IRequestReplyRouter)

  • B . B. Change line 03 as follows 如下更改03行

    typeof((IDuplexSessionRouter) typeof((IDuplexSessionRouter)

  • C . C. Change line 10 as follows 如下更改第10行

    typeof((IRequestReplyRouter) typeof((IRequestReplyRouter)

  • D . D. Change line 10 as follows 如下更改第10行

    typeof((IDuplexSessionRouter) typeof((IDuplexSessionRouter)

They says the correct answer is the B but I can't understand(and I need to understand :)). 他们说正确的答案是B,但我听不懂(我需要听懂:))。 I would have answered response A , since there is no callback methods, we don't need to have DuplexSessionRouter, no? 我会回答A ,因为没有回调方法,所以我们不需要DuplexSessionRouter,不是吗? And then a IRequestReply should be enough? 然后一个IRequestReply应该足够了吗?

What am I missing? 我想念什么?

The Routing Service uses contracts that define the shape of the channels used to receive and send messages, and therefore the shape of the input channel must match that of the output channel. 路由服务使用协定来定义用于接收和发送消息的通道的形状,因此输入通道的形状必须与输出通道的形状匹配。

So if you perform routing to endpoints that use the request-reply channel shape, then you must use a compatible contract on the inbound endpoints, such as the IRequestReplyRouter. 因此,如果执行到使用请求-答复通道形状的端点的路由,则必须在入站端点(例如IRequestReplyRouter)上使用兼容协定。

This means that if your destination endpoints use contracts with multiple communication patterns (such as mixing one-way and two-way operations) you cannot create a single service endpoint that can receive and route messages to all of them. 这意味着,如果目标端点使用具有多种通信模式的合同(例如,混合单向和双向操作),则无法创建可以接收消息并将消息路由到所有服务的单个服务端点。 A workaround is to use a duplex contract at the Routing Service such as IDuplexSessionRouter. 解决方法是在路由服务(例如IDuplexSessionRouter)上使用双工协定。

References: 参考文献:

http://msdn.microsoft.com/en-us/magazine/cc546553.aspx http://msdn.microsoft.com/zh-CN/magazine/cc546553.aspx

http://msdn.microsoft.com/en-us/library/ee517422.aspx http://msdn.microsoft.com/en-us/library/ee517422.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM