ASP.NET and Web Services, Part 1 - More SOAP Attributes
(Page 9 of 9 )
The Actor Attribute
The Actor attribute provides a mechanism for annotating SOAP headers. For example, a document can be routed to an intermediary that will create a transaction, specifying the URI for the intermediary for which a portion of the message is intended.
If the header is destined for processing by the next recipient of a SOAP message, set both the mustUnderstand attribute and the Actor attribute. Listing 4 demonstrates how to do this.
Listing 4 Setting the next recipient
<?xml version="1.0" encoding="utf-8"? >
<soap:Envelope xmlns:soap="http:////schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<TransactionID soap:mustUnderstand="1"
actor="urn:TransactionCoordinator>19.90</TransactionID>
</soapHeader>
<soap:Body>
<UpdateStockQuote>
<Source>102420484096</Source>
<Destination>102420484096</Destination>
<Price>12.95></Price>
</AddNewClient>
</soap:Body>
</soap:Envelope>
If the TransactionCoordinator does not know how to interpret this message, it raises an error. The directive does not belong in this message. This is evidenced by lack of a corresponding opening tag. Before the message is passed on, all foreign elements must be removed. However, the intermediary can add header elements before forwarding the message to the next intermediary or final recipient.
The Body Element
All SOAP messages must have exactly one element. The body element contains the payload. There are some constraints on how the body is encoded. The payload can consist of a string of ASCII characters, a byte array, or XML text. However, the contents may not contain any characters that would invalidate the embedded XML document. XML messages can be placed in two categories: document-oriented messages and procedure-oriented messages. For example, a document that provides a stock quote to a client can be encoded within the body of a SOAP message and specify a particular
routing for an intended recipient. The procedure-oriented messages offer two-way communications and are frequently referred to as RPC messages.
The Fault Element
SOAP messages fail for a number of reasons. It is important to use the Fault attribute and generate an error message back to a client. SOAP specifies a format for handling errors. Listing 5 demonstrates this.
Listing 5 Web services error handling
<?xml version="1.0" encoding="utf-8"? >
<soap:Envelope xmlns:soap="http:////schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<soap:FaultCode>Client.Security</soap:faultcode>
<soap:faultstring>Access denied</soap:faultstring>
<soap:faultactor>http://dps.com</soap:faultactor>
<soap:detail>
<myError>
<Originator>File System></Originator>
<Resource>My File.txt></Resource>
</myError>
</soap:detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
The Faultcode contains a value to determine the kind of error it encounters. Several fault codes are available for use:
- Version Mismatch This specifies an invalid namespace declared for the SOAP envelope.
- MustUnderstand A child element residing within the SOAP header contains a mustUnderstand attribute. If the attribute is set to 1, it indicates the attribute was not understood.
- Client Content located within the message body was found to be faulty.
- Server The server determines that the error lies with the inability to obtain resources or the inability to process the message.
The SOAP features presented here must be adhered to when processing SOAP messages. The next major web services technology, Web Services Description Language (WSDL), describes what a SOAP payload contains.
Remember: This is part one of chapter 7 .NET & J2EE Interoperability, by Dwight Peltzer (McGraw-Hill/Osborne, ISBN 0-07-223054-1, 2004). If you like what you see, feel free to click on the following link to get your own copy! Buy this book now.
|
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |