WCF Router: one way and request-reply operations

谁说胖子不能爱 提交于 2019-12-11 10:02:18

问题


In order to prepare my 70-513 exam, I found this questions:

A Windows Communication Foundation (WCF) service implements a contract with one-way and request-reply operations. The service is exposed over a TCP Transport. 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. Change line 03 as follows

    typeof((IRequestReplyRouter)

  • B. Change line 03 as follows

    typeof((IDuplexSessionRouter)

  • C. Change line 10 as follows

    typeof((IRequestReplyRouter)

  • D. Change line 10 as follows

    typeof((IDuplexSessionRouter)

They says the correct answer is the B but I can't understand(and I need to understand :)). I would have answered response A, since there is no callback methods, we don't need to have DuplexSessionRouter, no? And then a IRequestReply should be enough?

What am I missing?


回答1:


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.

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.

References:

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

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



来源:https://stackoverflow.com/questions/10911344/wcf-router-one-way-and-request-reply-operations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!