[Import] WCF post-transfer series (1): go deep into the WCF addressing Part 1-Web Service Addressing Specification

Source: Internet
Author: User
Overview

As we all know, all communication of a WCF Service occurs through the service endpoint. Each service endpoint contains an address, a binding, and a contract Contract. The contract specifies available operations, binding specifies how to communicate with the service, and the address specifies the location of the search service, that is, the very classic "ABC ". WCF uses a variety of different communication protocols to provide a flexible mode for public service endpoints and communication with them. In the first part of the WCF topic series, I will discuss the addressing details of endpoints, before that, let's take a look at the WCF programming model, as shown in 1:

Figure 1

Web Service Addressing Specification

In WCF, an endpoint address is an endpoint reference (EPR) model established according to the definitions in the WS-Addressing Specification for Web service addressing, we need to understand the Web service addressing specification. Here we first raise a question: why do we need web service addressing? On the one hand, if soap is to be truly unrelated to the transmission protocol, it is necessary to define the receiver of the message and the address returned by the message in a way unrelated to the transmission protocol; on the other hand, defining addressing information helps to return a message to the requester in the event of a network error or a loss of response. The last set of addressing mechanisms makes the complex interaction mode possible, as shown in Figure 2:

Figure 2

In WS-Addressing, there are actually two concepts: endpoint reference and message information headers in the soap structure ). The following example shows sending a soap 1.2 message to http://fabrikam123.com/purchasing. :

 <  S: Envelope  Xmlns: S = " Http://www.w3.org/2002/12/soap-envelope " Xmlns: WSA  = " Http://schemas.xmlsoap.org/ws/2003/03/addressing " > <  S: Header  > <  WSA: replyto  > <  WSA: Address  > Http://business456.com/client1 </  WSA: Address > </  WSA: replyto  > <  WSA:  > Http://fabrikam123.com/Purchasing </  WSA:  > <  WSA: Action  > Http://fabrikam123.com/SubmitPO </  WSA: Action  > </  S: Header  > < S: Body  > ...... </  S: Body  > </  S: Envelope  > 

Endpoint reference

A Web service endpoint is a referenced entity, processor, or resource that can be used as a Web Service Message target. An endpoint reference conveys the information required to identify or reference a web service endpoint, it can be used in a variety of ways: the endpoint reference can be used to convey the information required to access the Web service endpoint, or to provide addresses for each message between Web Services. See the followingCodeIndicates the information set referenced by the endpoint:

 <  WSA: endpointreference  > <  WSA: Address  > Xs: anyuri </ WSA: Address  > <  WSA: referenceproperties  >... </  WSA: referenceproperties  >? <  WSA: referenceparameters  >... </  WSA: referenceparameters  >? <  WSA: porttype  > Xs: QNAME </  WSA: porttype  >? <  WSA: servicename Portname  = "XS: ncname"?> Xs: QNAME </  WSA: servicename  >? <  WSA: Policies  >... </  WSA: Policies  >? <  Xs: Any  /> * </  WSA: endpointreference  > 

In the simplest sense, an endpoint reference is a URL encapsulated using XML elements, as shown in the following code:

<WSA: mylocation> <WSA: Address> Http: // localhost: 8887/calculatorservice </WSA: Address> </WSA: mylocation>

Here, WSA: mylocation refers to the endpoint reference, which is an element defined in the Web service addressing specification. It is used to specify the address used to access the calculatorservice. As part of the endpoint reference model, each endpoint reference can contain reference parameters that add additional identifiers.

Message Header

Message Information headers are some additional and standard SOAP Headers defined in the Web service addressing specification. They are used to help transmit information about a message, which is different from the endpoint reference, the message information header is included in the SOAP message as an extension of the soap head. Its information set is as follows:

 <  WSA:  > Xs: anyuri </ WSA:  >? <  WSA: From  > WSA: endpointreferencetype </  WSA: From  >? <  WSA: replyto  > WSA: endpointreferencetype </  WSA: replyto  >? <  WSA: faul.pdf  > WSA: endpointreferencetype </  WSA: faul.pdf  >? <  WSA: Action > Xs: anyuri </  WSA: Action  > <  WSA: messageid  > Xs: anyuri </  WSA: messageid  >? <  WSA: relatesto  Relationshiptype  = "XS: anyuri"?> Xs: anyuri </  WSA: relatesto  > * <  WSA: referenceparameters  > Xs: Any * </  WSA: referenceparameters >? 

Let's explain it as follows:

To: Indicates the URL of the target Web Service. When using the endpoint reference (EPR), The to header should have the same value as the <WSA: Address> element.

From: Indicates the end point reference of the message sender. If the message receiver needs to send back the message to the end point of the sent message, it should use this end point reference.

Replyto: Indicates that any response from the Web service should be sent to the replyto endpoint for reference. That is, the sender of the message is not necessarily the end point of the response message to be received, this is different from.

Faul.pdf: If the message response is a soap error, the error should be sent to the endpoint reference in the faultto header.

Messageid: Uniquely identifies a message.

Action: The action can be understood in this way. When a message is sent to a service, it is simpler to specify the method to be called by the Service to process the message. The following code is used to call the add method when you want the message to arrive at the service.

 
<WSA: Action>Http://tempuri.org/ICalculator/Add</WSA: Action>

Relatesto: Relatesto is often used in response messages to indicate a URI that is related to a previously known message and defines this relationship. This is critical in the request response mode, especially in asynchronous message transmission. the receiver of the response message must be able to associate it with the original request message.

We use Figure 3 to clearly express the message headers and soap in the message header:

Figure 3

For details about the WS-Addressing specification, refer to http://www.w3.org/submission/ws-addressing /.

Analyze WCF messages

I have introduced the Web Service Addressing Specification above. Now we can intercept the message of WCF to see how it complies with WS-Addressing. Write a simple WCF Service:

/// <Summary> ///Author: terrylee///URL: http://www.cnblogs.com/terrylee/// </Summary>[Servicecontract]Public interfaceIcalculator{[Operationcontract]IntAdd (IntX,IntY );}Public classCalculatorservice:Icalculator{Public intAdd (IntX,IntY ){ReturnX + Y ;}}

We can use tracking and diagnosis to intercept soap messages, as shown below. We can see the to address and action in the message header during this service call, the action here is the add method defined in the Service and the body of the message:

 <  S: Envelope  Xmlns: S  = " Http://schemas.xmlsoap.org/soap/envelope/ " > <  S: Header  > <  To  S: mustunderstand  = " 1 " > Http: // localhost: 8887/calculatorservice </  To  > <  Action  S: mustunderstand  = " 1 " > Http://tempuri.org/ICalculator/Add </  Action  > </  S: Header  > <  S: Body  > < Add  Xmlns  = " Http://tempuri.org/ " > <  X  > 1 </  X  > <  Y  > 2 </  Y  > </  Add  > </ S: Body  > </  S: Envelope  > 

Conclusion

The Web Service Addressing Specification brings the addressing standard of the web service world. It defines the endpoint reference and message information headers) to provide a unified mechanism. In the next article, I will continue to analyze the addressing and WCF addressing problems inArticle:

WCF topic series (5): go deep into WCF addressing Part 5-Logical Address and physical address

WCF topic series (4): go deep into WCF addressing Part 4-custom message Filter

WCF topic series (3): go deep into WCF addressing Part 3-message filtering engine

WCF topic series (2): go deep into WCF addressing Part 2-custom addressing Header

--------------------------
News: China's Yahoo sales team rebuilt to make money and put it to the strategic height
In the left-side navigation pane of the blogs homepage, click "Knowledge Base", and click "Search ".
Source: http://www.cnblogs.com/Terrylee/archive/2008/10/25/WCF-addressing-part1.html

Related Article

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.