XML-Based Protocols


This article has been excerpted from book "The Complete Visual C# Programmer's Guide" from the Authors of C# Corner.

This section reviews XML-based protocols. The information we present here is bundled from official documents. It is important to understand which component fits where. Please refer to the World Wide Web Consortium (W3C) XML Protocol Comparisons Web page (http://www.w3.org/2000/03/29-XML-protocol-matrix/) to compare and contrast a variety of XML protocols. Also note that the XML Schema Definition Tool (Xsd.exe) will help you if you want to use the produced XML files extensively, because it can output XML schema or CLR classes from XDR (XML-Data-Reduced), XML, and XSD (XML Schema Definition) files or from classes in a runtime assembly. Only XML-based protocols in which Microsoft participated are discussed here.

DISCO

Developers will need a way to discover Web services. Discovery of Web Services (DISCO) provides a way to discover and retrieve WSDL descriptions of services on remote machines. Using the discovery document format (which is also an XML grammar), one can send a discovery document to a remote server and, if any SOAP-enabled services (i.e., Web services) exist, receive back a WSDL description of the services provided. In many cases, developers will not know the URLs of the services. Universal Description, Discovery, and Integration (UDDI) specifies a mechanism whereby Web service providers advertise the existence of their Web services and Web service consumers locate Web services of interest. UDDI is a specification for distributed Webbased information registries of Web services. UDDI is also a publicly accessible set of implementations of the specification that allows businesses to register information about the Web services they offer so that other businesses can find them. UDDI registries are used to promote and discover distributed Web services. The Web Services Discovery Tool (Disco.exe) helps you discover the URLs of Web services located on a Web server. You can also save documents related to each Web service locally. Listing 23.28 shows a sample DISCO document from W3C.

Listing 23.28: A DISCO Document


<
disco:discovery>
          <
disco:discoveryRef ref='folder/discovery'/>
          <
-- elements from other namespaces -->
</
disco:discovery>
<
disco:discovery>
          <
scl:contractRef ref='my1.sdl'>
                   <
scl:contractRef ref='my2.sdl' docRef='my.htm'>
</
disco:discovery>
<
disco:discovery>
          <
schema:schemaRef ref='my1.xsd' targetNamespace='http://my.org/my1.xsd'/>
          <
schema:schemaRef ref='my2.xsd'/>
</
disco:discovery>

UDDI

UDDI is a building block that enables businesses to quickly, easily, and dynamically find and transact business with one another using their preferred applications. UDDI is designed to provide a searchable directory of businesses and their Web services. A sample UDDI document from W3C appears in Listing 23.29.

Listing 23.29: An UDDI Document


<
element name="businessEntity">
          <
type content="elementOnly">
                   <
group order="seq">
                             <
element ref="discoveryURLs" minOccurs="0" maxOccurs="1"/>
                             <
element ref="name"/>
                             <
element ref="description" minOccurs="0" maxOccurs="*"/>
                             <
element ref="contacts" minOccurs="0" maxOccurs="1"/>
                             <
element ref="businessServices" minOccurs="0" maxOccurs="1"/>
                             <
element ref="identifierBag" minOccurs="0" maxOccurs="1"/>
                             <
element ref="categoryBag" minOccurs="0" maxOccurs="1"/>
                   </
group>
                   <
attribute name="businessKey" minOccurs="1" type="string"/>
                   <
attribute name="operator" type="string"/>
                   <
attribute name="authorizedName" type="string"/>
          </
type>
</
element>

WSDL

Given a Web service, it would be nice to have a standard way to document what messages the Web service accepts and generates-that is, to document the Web service contract. A standard language makes it easy for developers and developer tools to create and interpret contracts. The Web Services Description Language (WSDL) is an XML-based contract language jointly developed by Microsoft and IBM. The Web services contract written using WSDL is an XML document that defines the inputs and outputs of a Web service, including the XML schemas that should be used to create the input and output documents. Each WSDL document contains both an abstract definition of the service and how the service binds to a particular network implementation and data format bindings.

Over the years Microsoft and IBM have proposed several contract languages: Service Description Language (SDL), Service Contract Language (SCL), and Network Accessible Services Specification Language (NASSL). All these are superceded by WSDL. WDSL is a new specification to describe networked XML-based services. It provides a simple way for service providers to describe the basic format of requests to their systems regardless of the underlying protocol (such as SOAP or XML) or encoding (such as Multipurpose Internet Messaging Extensions). WSDL is a key part of the effort of the UDDI initiative to provide directories and descriptions of such online services for electronic business. You can use the Web Services Description Language Tool (Wsdl.exe) to generate WSDL files for ASP.NET Web services-in other words, usable codes from WSDL contract files, XSD schemas, and .discomap discovery documents. Listing 23.30 shows an example of a WSDL document from W3C.

Listing 23.30: A WSDL Document

<?
xml version="1.0"?>
<
definitions name="StockQuote"
targetNamespace
="http://example.com/stockquote.wsdl"
xmlns:tns
="http://example.com/stockquote.wsdl"
xmlns:xsd1
="http://example.com/stockquote.xsd"
xmlns:soap
="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns
="http://schemas.xmlsoap.org/wsdl/">
          <
types>
                   <
schema targetNamespace="http://example.com/stockquote.xsd"
                  
xmlns="http://www.w3.org/1999/XMLSchema">
                             <
element name="TradePriceRequest">
                                      <
complexType>
                                                <
all>
                                                          <
element name="tickerSymbol" type="string"/>
                                                </
all>
                                      </
complexType>
                             </
element>
                             <
element name="TradePrice">
                                      <
complexType>
                                                <
all>
                                                          <
element name="price" type="float"/>
                                                </
all>
                                      </
complexType>
                             </
element>
                   </
schema>
          </
types>
          <
message name="GetLastTradePriceInput">
                   <
part name="body" element="xsd1:TradePrice"/>
          </
message>
          <
message name="GetLastTradePriceOutput">
                   <
part name="body" element="xsd1:TradePriceResult"/>
          </
message>
          <
portType name="StockQuotePortType">
                   <
operation name="GetLastTradePrice">
                             <
input message="tns:GetLastTradePriceInput"/>
                             <
output message="tns:GetLastTradePriceOutput"/>
                   </
operation>
          </
portType>
          <
binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType">
                   <
soap:binding style="document"
                  
transport="http://schemas.xmlsoap.org/soap/http"/>
                   <
operation name="GetLastTradePrice">
                             <
soap:operation soapAction="http://example.com/GetLastTradePrice"/>
                             <
input>
                                      <
soap:body use="literal"
                                     
namespace="http://example.com/stockquote.xsd"
                                     
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
                             </
input>
                             <
output>
                                      <
soap:body use="literal"
                                     
namespace="http://example.com/stockquote."          encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
                             </
output>
                   </
operation>
          </
binding>
          <
service name="StockQuoteService">
                   <
documentation>My first service</documentation>
                   <
port name="StockQuotePort" binding="tns:StockQuoteBinding">
                             <
soap:address location="http://example.com/stockquote"/>
                   </
port>
          </
service>
</
definitions>xsd"

SOAP

Simple Object Access Protocol (SOAP) is a lightweight, XML-based protocol for exchange of information in a decentralized, distributed environment. It consists of three parts: an envelope that defines a framework for describing what is in a message and how to process it, a set of encoding rules for expressing instances of application-defined data types, and a convention for representing remote procedure calls and responses. SOAP can potentially be used in combination with a variety of other protocols; however, the only bindings defined in the SOAP specification describe how to use SOAP in combination with HTTP and HTTP Extension Framework. The Soapsuds tool (Soapsuds.exe) creates XML schemas describing services exposed so you can compile client applications that communicate with Web services using a technique called remoting. A sample SOAP document from W3C appears in Listing 23.31.

Listing 23.31: A SOAP Document


<
SOAP-ENV:Envelope
xmlns:SOAP-ENV
="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingStyle
="http://schemas.xmlsoap.org/soap/encoding/"/>
<
SOAP-ENV:Body>
          <
e:Book>
                   <
title>My Life and Work</title>
                   <
firstauthor href="#Person-1"/>
                   <
secondauthor href="#Person-2"/>
          </
e:Book>
          <
e:Person id="Person-1">
                   <
name>Henry Ford</name>
                   <
address xsi:type="m:Electronic-address">
                             <
email>mailto:[email protected]</email>
                             <
web>http://www.henryford.com</web>
                   </
address>
          </
e:Person>
          <
e:Person id="Person-2">
                   <
name>Samuel Crowther</name>
                   <
address xsi:type="n:Street-address">
                             <
street>Martin Luther King Rd</street>
                             <
city>Raleigh</city>
                             <
state>North Carolina</state>
                   </
address>
          </
e:Person>
</
SOAP-ENV:Body>
</
SOAP-ENV:Envelope>

BizTalk

Official information about the BizTalk protocol is available at http://www.biztalk.org/. Microsoft has also put a back-office product called BizTalk server on the market to make it easier to develop and deploy BizTalk-based business-to-business, business-to-customer, customer-to-business, and customer-to-customer applications between internal and external commodity merchandisers.

The Microsoft BizTalk Framework is an XML framework for application integration and electronic commerce. It includes a design framework for implementing an XML schema and a set of XML tags used in messages sent between applications. Microsoft, other software companies, and industry standards groups can use the BizTalk Framework to create XML schemas in a consistent manner. The BizTalk Framework itself is not a standard: XML is the standard. The goal of the BizTalk Framework is to accelerate the rapid adoption of XML. BizTalk Framework schemas, which are business documents and messages expressed in XML, can be registered and stored on the BizTalk.org Web site.

Any individual or organization can download the framework and use it to create and submit an XML schema to the Web site. As long as the schema passes a verification test, it is considered a valid BizTalk Framework schema. Individuals and organizations can freely use XML schemas from the BizTalk.org Web site in their applications for as long as the schema is published for public use. The BizTalk Framework schema design has been submitted to W3C for adoption as an XML schema standard. A sample BizTalk document from W3C appears in Listing 23.32.

Listing 23.32: A BizTalk Document


<
SOAP-ENV:Envelope
xmlns:SOAP-ENV
="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi
="http://www.w3.org/1999/XMLSchema-instance">
          <
SOAP-ENV:Header>
                   <
dlv:delivery SOAP-ENV:mustUnderstand="1"
                  
xmlns:dlv="http://schemas.biztalk.org/btf-2-0/delivery"
                  
xmlns:agr="http://www.trading-agreements.org/types/">
                             <
dlv:to>
                                      <
dlv:address xsi:type="agr:department">
                                                Book Order
                                                Department

                                      </
dlv:address>
                             </
dlv:to>
                             <
dlv:from>
                                      <
dlv:address xsi:type="agr:organization">
                                                Booklovers
                                                Anonymous

                                      </
dlv:address>
                             </
dlv:from>
                   </
dlv:delivery>
                   <
prop:properties SOAP-ENV:mustUnderstand="1"
                  
xmlns:prop="http://schemas.biztalk.org/btf-2-0/properties">
                             <
prop:identity>uuid:74b9f5d0-33fb-4a81-b02b-5b760641c1d6</prop:identity>
                             <
prop:sentAt>2000-05-14T03:00:00+08:00</prop:sentAt>
                             <
prop:expiresAt>2000-05-15T04:00:00+08:00</prop:expiresAt>
                             <
prop:topic>http://electrocommerce.org/purchase_order/</prop:topic>
                   </
prop:properties>
          </
SOAP-ENV:Header>
          <
SOAP-ENV:Body>
                   <
po:PurchaseOrder
                  
xmlns:po="http://electrocommerce.org/purchase_order/">
                             <
po:Title>Essential BizTalk</po:Title>
                   </
po:PurchaseOrder>
          </
SOAP-ENV:Body>
</
SOAP-ENV:Envelope>

Conclusion

Hope this article would have helped you in understanding XML-Based Protocols. See other articles on the website on .NET and C#.

visual C-sharp.jpg The Complete Visual C# Programmer's Guide covers most of the major components that make up C# and the .net environment. The book is geared toward the intermediate programmer, but contains enough material to satisfy the advanced developer.


Similar Articles