简体   繁体   中英

WCF Router: one way and request-reply operations

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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