Invoking web Services using SOAP messages

Source: Internet
Author: User
Tags abstract abstract definition format definition http post version web services access
Services|web Web Services technology enables heterogeneous computing environments to share data and communication to achieve information consistency. As the environment of heterogeneous computers is increasing, we will invoke Web services written and published in various computer systems more often, and the author gives the practical process of using VB application to invoke Web services written and published by the Java platform. It also analyzes how to construct a SOAP message based on a WSDL file.

A SOAP Introduction

1.SOAP definition

SOAP (Simple Object access Protocol) is an xml-based protocol that is a simple protocol for exchanging information in a decentralized or distributed environment.

It consists of four sections:

Soap Encapsulation (envelop): encapsulation defines a framework that describes what the content in the message is, who sent it, who should accept and handle it, and how to handle it;
SOAP encoding rule (encoding Rules): an instance of the data type that the application needs to use;
SOAP RPC Representation (RPC representation): A contract that represents a remote procedure call and answer;
SOAP binding (binding): exchanging information using the underlying protocol.

2.SOAP message

SOAP employs two protocols that have been widely used: HTTP and XML. Where HTTP is used to implement SOAP's RPC-style transmission, and XML is its encoding pattern, a SOAP request is actually an HTTP POST request.

For additional details on the soap side, please refer to http://www.w3.org/TR/2001/WD-soap12-20010709/

Introduction to two WSDL

The WSDL (Web Services Description Language) is an XML application that describes a Web services as a set of service access points.

A WSDL document describes a Web service as a set of network endpoints or ports, and in WSDL, these abstract objects can be reused because the abstract definition of the services access point and message is separated from the specific service deployment and data format bindings: message, an abstract description of the information that needs to be exchanged The port type, which is an abstract collection of operations provided by the Web service.

The specific protocol and data format definitions for a particular port type form a binding that can be used, a port defined as a reusable binding and a network address, and a set of ports constitutes a service.

The WSDL uses the following elements when defining Web Sevices:

Types: A container of data types, he uses some type systems (such as commonly used XSD)
Message: Abstract typed definition of communication messages
Operation: Abstract Description of the operations provided by the service
Port Type: An abstraction of a set of operations supported by one or more endpoints
Binding: Specific protocol and data format definitions for specific port types
Port: A single endpoint defined as an association of binding and network addresses
Service: The combination of a set of related endpoints

Detailed WSDL definition and related information please refer to: http://www.w3c.org/TR/wsdl

Three uses WSAD to develop and publish a Web Services

1. We created a HelloWorld Java class with Wsad (Websphere Studio application Developer), and he had only one way to return a string HelloWorld.

Helloworld.java

Package Hello;

public class HelloWorld {
Public String getString () {
Return "Hello world!";
}
}

2. Publish this class as a Web service on a server with a test environment in WASD

After publishing, we can find two. wsdl files under the WSDL file for the Web project: HELLOWORLD-SERVICE.WSDL, The helloworld-binding.wsdl,helloworld-binding.wsdl file mainly describes the service access point for this Web services, and the helloworld-binding.wsdl file describes the Web Information about the data structure of the communication messages for services, the operations supported by each access point, the specific protocols for specific fracture types, and the binding of data format specifications can refer to the deployment of WEB services using WSDL:

Part 1th (http://www-900.cn.ibm.com/developerworks/cn/webservices/ws-intwsdl/part1/index.shtml) The contents of HELLOWORLD-SERVICE.WSDL are as follows:




<definitions name= "HelloWorldService" targetnamespace= "http://localhost:808/WForecast/wsdl/HelloWorld-service.wsdl"
xmlns= "http://schemas.xmlsoap.org/wsdl/" xmlns:tns= "http://localhost:808/WForecast/wsdl/HelloWorld-service.wsdl "
Xmlns:binding= "Http://www.helloworld.com/definitions/HelloWorldRemoteInterface"
xmlns:soap= "http://schemas.xmlsoap.org/wsdl/soap/" >
<import namespace= "Http://www.helloworld.com/definitions/HelloWorldRemoteInterface"
location= "http://localhost:808/WForecast/wsdl/HelloWorld-binding.wsdl"/>
<service name= "HelloWorldService" >
<port name= "Helloworldport" binding= "binding:helloworldbinding" >
<soap:address location= "Http://localhost:808/WForecast/servlet/rpcrouter"/>
</port>
</service>
</definitions>

The contents of HELLOWORLD-BINDING.WSDL are as follows:

--><?xml version= "1.0" encoding= "UTF-8"?>
<definitions name= "Helloworldremoteinterface"
Targetnamespace= "Http://www.helloworld.com/definitions/HelloWorldRemoteInterface"
Xmlns= "http://schemas.xmlsoap.org/wsdl/"
Xmlns:tns= "Http://www.helloworld.com/definitions/HelloWorldRemoteInterface"
Xmlns:xsd= "Http://www.w3.org/2001/XMLSchema" xmlns:soap= "http://schemas.xmlsoap.org/wsdl/soap/" >
<message name= "GetString" >
<part name= "Result" type= "xsd:string"/>
</message>
<porttype name= "Helloworldjavaporttype" >
<operation name= "GetString" >
<output name= "getString" message= "tns:getstring"/>
</operation>
</portType>
<binding name= "helloworldbinding" type= "Tns:helloworldjavaporttype" >
<soap:binding style= "rpc" transport= "Http://schemas.xmlsoap.org/soap/http"/>
<operation name= "GetString" >
<soap:operation soapaction= "" style= "rpc"/>
<output name= "GetString" >
<soap:body use= "encoded" encodingstyle= "http://schemas.xmlsoap.org/soap/encoding/" namespace= "Urn:helloworld"/ >
</output>
</operation>
</binding>
</definitions>

3. Start the test server in Wsad

[1] [2] Next page



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.