Resource
|
Reference
[JIBJAB] Alexa Traffic Monitor for jibjab.com www.
|
Chapter 4. Web Services for Synchronous Integration |
Web Services Technology OverviewThere are a number of ways to describe Web services, but for the purpose of using a standard definition this book uses the W3C definition of a Web service:
In a typical Web services scenario, a business application that could be a Web service uses SOAP message, usually over the HTTP transport protocol, to send a request to another service at a URL. The service receives the request, processes it, and returns a response. In a supply chain scenario, Web services and their consumers are typically businesses, making Web services predominantly business-to-business (B2B) transactions. An enterprise can be the Web service provider and also the consumer of other Web services. For example, a wholesale distributor of spices is in the consumer role when it uses a Web service to check on the availability of vanilla beans and in the provider role when it
Problem
Integrating diverse business applications into a cohesive, reliable, and secure architecture is a common challenge that most
Figure 4-1. Sample scenario
As can be told from this diagram, the
SolutionWeb services have become a de facto standard to effectively achieve interoperability across diverse sets of enterprise applications and offer a preferred technology choice for integration. Here is the reason why: Interoperability, simplicity, XML-based human readable format, and ease of use help streamline inter-application communication. Therefore, Web services are widely used for both B2B as well as corporate inter-application integration. Conceptually the Web service model involves the following elements:
Web services often used to enable Service Oriented Architecture (SOA), with the primary goal of Web Services Architecture (WSA) being to promote interoperability. Web services provide a means of interoperability across heterogeneous systems, platforms, applications, and programming languages. As part of that, Web services present a useful mechanism for integration of Java EE applications with those built on the Microsoft .NET Framework. When using Web services for interoperability between Java EE and Microsoft .NET, you can gain a lot of architectural flexibility. Because they are XML-based, loosely
Web Service TechnologiesWeb services are fueled by XML, which, being a markup language, enables neutrality of platform, language, and vendor. XML is also the key to the loosely coupled nature of Web services. A Web service is an abstract entity defined by an XML-based interface, Web Services Description Language (WSDL), and communicated using an XML-based protocol (SOAP) or Representational State Transfer (REST). This is the essence of the Web services value propositionthe abstract nature of the Web service definition, discovery, and communication, the underlying implementation, be it .NET, Java EE, or something else is completely abstracted away from the consumer. Similarly, there is a flexibility of sending SOAP messages over HTTP/S, FTP, or SMTP transport protocols. SOAP is the technology used for communicating with Web services. While very simple information transfer services can be implemented without SOAP, secure, reliable, multi-part, multi-party and/or multi-network applications are much easier to build if there is a standard way of packaging the messaging information in a protocol neutral way. This also allows the messaging infrastructure (which may be specialized hardware, SOAP intermediaries, or code libraries called by the ultimate recipient of a SOAP message) to provide authentication, encryption, access control, transaction processing, routing, and delivery confirmation services. SOAP envelope (and attachment) structure and header/processing models have proven to be a very robust and powerful framework within which to do this.
Interoperability across heterogeneous systems requires a mechanism to allow the precise structure and data types of the messages to be commonly
WSDL, SOAP, and UDDI act as the
Java Web ServicesOn the Java side, several Java technologies work together to provide support for Web services. These technologies can be accessed via Java Web Services Developer Pack (JWSDP) toolkit or corresponding development tools that might be used to construct Web services. Please refer to [JWSDP] for details and download.
As a starting point, the Java API for XML-Based RPC (JAX-RPC) provides support for Web services using the SOAP over HTTP. JAX-RPC defines the mapping between Java classes and XML as used in SOAP RPC calls. Multiple examples in this book are implemented with JAX-RPC, demonstrating a diverse set of scenarios in which the developer can utilize this technology. With JAX-RPC and a WSDL, one can easily
Figure 4-2. JAX-RPC overview
On the client side, there are stubs corresponding to Web services, while on the server side Web services are compiled into the corresponding ties. The underlying message and transport protocol should be the same to ensure interoperability between a client and a server. Please refer to [JAX-RPC] for more details. There are three modes in which a JAX-RPC client can interact with the server. The first one is a traditional synchronous
Aside from JAX-RPC, Java Web Services include the SOAP with Attachments API for Java (SAAJ) [SAAJ]. This API is used to pass business documents (in binary format) by attaching them to the SOAP message. To ensure interoperability of the binary data attachments in the SOAP document, both Java Web Services (via JAX-WS) and .NET offer the SOAP Message Transmission Optimization Mechanism (MTOM), [MTOM].
Developer's Note
Since the release of JAX-RPC 1.0, new specifications and new versions of the standards that it implements have been released. JAX-WS 2.0 [JAX-WS] is the successor to JAX-RPC and
Additionally, it extends and
As part of the SOA, services are often published in the UDDI registry. The Java API for XML Registries [JAXR] provides client access to the XML registry. The Java API for XML Registries [JAXR] allows access to business and general-purpose registries over the Web. JAXR supports the ebXML Registry/Repository standards and the UDDI specifications. The Java Web Service Developer Pack also includes APIs to bind XML schemas to Java classes, provided by the Java Architecture for XML Binding (JAXB) [JAXB]. The JAXB binding compiler can be used to automatically generate Java domain objects. Document parsing and transformation often are necessary operations for Web services. For that you can use the Java API for XML Processing (JAXP) [JAXP] that supports processing of XML documents. JAXP can be used with Document Object Model (DOM), Simple API for XML Parsing (SAX), and XML Style sheet Language Transformation (XSLT). Table 4-1 contains a summary of common APIs included in the Java Web Services Developer Pack: Table 4-1. Java Web Services API Summary
Perhaps the most important feature of the Java EE APIs for Web services and XML is that they all support industry standards, thus ensuring interoperability. Various network interoperability standards groups, such as the World Wide Web Consortium (W3C) and the Organization for the Advancement of Structured Information Standards (OASIS), have been defining Web services standards to allow disparate applications to seamlessly integrate with each other. Web Services in Microsoft .NET Framework
Microsoft .NET provides two mechanisms for building Web services. The first and more widely used approach to implement Web services is to use the Microsoft .NET System.Web.Webservices namespace in the .NET Framework. A server application might have its methods defined as Web
Another technique is to write a custom HTTP handler class that plugs into the Microsoft .NET HTTP pipeline by implementing the
IHTTPHandler
interface. HTTP Handlers are objects that process
The latter methodology allows for greater flexibilityparticularly when there is the need to pre- or post-process the contents of the SOAP message, but for the sake of simplicity the former is used throughout this book. On the client side, proxies are used to communicate with a Web service. These proxies are automatically generated by the wsdl.exe tool that is available within the .NET Framework or from Visual Studio.NET. These proxies, once included in a project and linked in when compiling code, manage communication with the Web methods that are exposed by the service. They are generated by parsing the WSDL file that describes the Web service.
XML Processing, which is central to Web services, is
XML can, of course, be used directly, using the classes within the System.Xml namespace [MSXML] to create, load, parse, and edit XML documents, including SOAP examples.
The .NET Framework does not include UDDI functionality by default. If you want to publish or
Following is an example of the UDDI SDK in action where the directory is being enquired for a particular service, and then the business services that match the enquiry are iterated:
UddiConnection myConn = new
UddiConnection("http://test.uddi.myserver.com/inquire");
GetServiceDetail gs = new GetServiceDetail(strKey);
ServiceDetail servDetail = gs.Send(myConn);
foreach (BusinessService bs in servDetail.BusinessServices)
{
...
}
To handle attachments such as Direct Internet Message Encapsulation (DIME) or Message Transmission Optimization Mechanism (MTOM), Microsoft has a suite of libraries as an add-on to the .NET Framework called the
Web Services Enhancement
For a complete guide on all things to do with Web services in the Microsoft and .NET world, the MSDN Web services developer portal is an
The Microsoft philosophy for software is very much centered around building software as atomic service-oriented components. It is with this in mind that the
|