Carry multiple endpoints in a single listenuri

Source: Internet
Author: User

This article is transferred from: http://technet.microsoft.com/zh-cn/library/aa395210 (vs.90). aspx

 

 

As described in the Multi-endpoint example, a service can host multiple endpoints, each of which has a different address and may have different bindings. This example demonstrates that multiple endpoints can be hosted at the same address, and the two endpoints of a Service (EndpointaddressAndListenuri.

EndpointaddressIs the service logic address, which is the address sent by the SOAP message.ListenuriIs the physical address of the service. It has the port and address information used when the service endpoint actually listens to messages on the current computer. In most cases, you do not need to differentiate these addresses.Listenuri, The address is the end point by default.Endpointaddress. In a few cases (for example, when configuring a vro), it is necessary to differentiate these addresses because the vro may accept messages sent to a large number of services.

Service

The service in this example has two agreements:IcalculatorAndIecho. Except for the commonImetadataexchangeThere are three more applications.ProgramEndpoint, as shown belowCode.

Copy
<Endpoint address = "urn: Stuff" binding = "wshttpbinding" Contract = "Microsoft. servicemodel. samples. icalculator "listenuri =" http: // localhost/servicemodelsamples/service. SVC "/> <endpoint address =" urn: Stuff "binding =" wshttpbinding "Contract =" Microsoft. servicemodel. samples. iecho "listenuri =" http: // localhost/servicemodelsamples/service. SVC "/> <endpoint address =" urn: otherecho "binding =" wshttpbinding "Contract =" Microsoft. servicemodel. samples. iecho "listenuri =" http: // localhost/servicemodelsamples/service. SVC "/>

All three endpoints are in the sameListenuriAnd use the sameBinding(That is, in the sameListenuriMust have the same binding), because they share a channel stack and the channel stack listens for messages on the physical address of the computer. TheAddressIt is an urn. Although the address usually represents a physical location, the address can actually be a URI of any type, because the address can be used for matching and filtering purposes, as shown in this example.

Because all three endpoints share the sameListenuriTherefore, when a message arrives, Windows Communication Foundation (WCF) must determine the end point to which the message is sent. Each endpoint has a message filter, which consists of an address filter and a protocol filter. Address FilterToMatches the endpoint address. For example, onlyTo "urn: otherecho"Is the third candidate endpoint of the service. The protocol filter matches the actions associated with specific protocol operations. For exampleIechoOperation message.EchoMatches the Protocol filters for the second and third endpoints of the service because both endpoints hostIechoAgreement.

Therefore, with this combination of address filter and protocol filter, you can reach the serviceListenuriRoute each message to the correct endpoint. The third endpoint is different from the other two because it accepts messages sent from other endpoints to another address. The difference between the first two endpoints is that their protocols (the actions for incoming messages) are different.

Client

Just as there are two different endpoints on the server, the client endpoints also have two addresses. On the server and client, the logical address is calledEndpointaddress. However, the physical address is calledListenuriIs calledVia.

On the server, the two addresses are the same by default. To specify a different endpoint address on the clientVia, You can useClientviabehavior:

Copy
 
Uri via = new uri ("http: // localhost/servicemodelsamples/service. SVC "); calculatorclient calcclient = new calculatorclient (); calcclient. channelfactory. endpoint. behaviors. add (New clientviabehavior ());

As usual, the client configuration file generated by svcutil.exe can be used as the address.Via(With the Service'sListenuriCorrespondingly) does not appear in the metadata of the service. Therefore, the information must be transferred to the client in the out-of-band mode (just like the metadata address of the Service ).

In this example, the client sends a message to the three application endpoints of each server to demonstrate that it can communicate with and differentiate these endpoints, even if these endpoints have the sameViaThis is also true.

Set, generate, and run examples
    1. Make sure that you have executed the one-time installation process for the Windows Communication Foundation example.

    2. To generate a solution for C # Or Visual Basic. net, follow the instructions in the example of generating windows Communication Foundation.

    3. If you want to run the example in standalone or cross-computer configuration, follow the instructions in the example of running Windows Communication Foundation.

      Note:
      To run the program on a different computer, you must replace localhost in the client. CS file with the name of the Service computer.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.