WebService Study Summary

Source: Internet
Author: User
Tags abstract definition soap mul wsdl

Why should there be webservice?

In network programming, often in different programs to exchange data, some programs using C language, some written in Java, and some in C # written ..., in order to facilitate the exchange of data between different platforms and transmission, there is a webservice this technology.

technologies that are widely used in the Web:
    1. TCP/IP: Universal network protocol, used by various devices
    2. HTML (an application under the standard Universal Markup Language): a common user interface that can display data using HTML tags
    3. . NET: Sharing data and data exchange among different applications
    4. Java: Write a common programming language that can run on any system, because Java has cross-platform features
    5. XML (a subset of standard common markup languages): a common data expression language, an easy way to transfer structured data over the web

First, WebService

WebService is a network-based, distributed, modular component that performs specific tasks, complies with specific technical specifications, and can interoperate with other compatible components.

WebService is an object or component that is deployed on a network.


Second, SOA

SOA (service-oriented Architecture) service-oriented architecture

SOA is a component model that links the different functional units (services) of an application to a well-defined interface and contract between these services.

The difference and connection between SOA and Web service

The difference between SOA service and Web service is the design

SOA does not define exactly how services interact, but simply defines how services understand each other and how they interact.

The difference is the difference between how the strategy of executing the process and the tactics of how the process is executed.

There are specific guidelines for how a WEB service can deliver messages between services that require interaction.

Web service is also one of the specific ways to implement SOA.

Characteristics of SOA:

    • Reuse of services (reuse)
    • Interoperability of services (interoperability)
    • The service is an autonomous (autonomous) functional entity
    • Loose coupling between services (loosly coupled)
    • Service is location-transparent (locations transparency)

Benefits of SOA:

    • Integrate existing systems without having to reinvent the system
    • The service design is loosely coupled, bringing many advantages
    • Unified Business Architecture, scalability enhancements
    • Speed up development and reduce development costs
    • Continuously improve business processes and reduce the risk of cataclysm

The lack of SOA:

    • Reliability: Not exactly the highest reliability for the transaction, non-repudiation, the message must be delivered and delivered only once, and the transaction is withdrawn ready.
    • Security: Because the components of one application are easy to talk to other components belonging to different domains, it is much more complex to ensure the security between different systems that are interconnected.
Third, WSDL

WSDL (Web service decription Language)-web Service Description Language

The Web Services Description Language specification defines an XML glossary that defines a contract between the service request and the service provider, in accordance with the request and response message.

3.1. Basic structure

The WSDL document can be divided into two parts, the top part consists of the abstract definition;

The bottom part is made up of specific descriptions.

Abstract definition

    • Types: Machine-and language-independent type definitions,
    • Message: include function parameters (input and output separate) or document description
    • Porttypes: The message definition in the Reference message section describes the function signature (Operation history, input parameters, output parameters)

Specific definition

    • Each operation of the Bindings:porttypes section is implemented in a binding
    • Servies: Determine the port address of each binding

Abstract elements:

Types element-Container for data type definitions

Message element-abstract type definition of the data structure of the communication message

porttype element--can describe the actions that a Web service can perform and related messages

Specific elements:

Binding elements-bindings for specific protocol and data format specifications for a particular port type

Service element-collection of related service access points

Iv. Soap Overview

SOAP (Simple Object access Protocol), an XML-based lightweight protocol for exchanging information in a distributed environment

SOAP consists of 4 parts:

    • SOAP Encapsulation: Encapsulation defines a framework that describes what the content in a message is, who is sent, who should accept and handle it, and how to handle it.
    • SOAP encoding Rules: an instance of the type of database that the application needs to use.
    • SOAP RPC representation: A contract that represents a remote procedure call and an answer
    • SOAP binding: Exchanging information using the underlying protocol.

The benefits of soap:

    • Relative to Vendor-independent
    • Relative to platform independence
    • independent of operating system
    • Independent of programming language

Transmission and language binding, and parameter selection of data encoding are determined by the implementation

4.1. SOAP
    • Soap is a simple Object Access protocol
    • SOAP is a communication protocol
    • SOAP is used for communication between applications
    • SOAP is a format for sending messages
    • SOAP is designed to communicate over the Internet
    • Soap independent of Platform
    • Soap independent of language
    • SOAP based XML
    • Soap can be extended
    • SOAP allows firewall bypass
    • SOAP will be developed as a beacon

5. UDDIThe purpose of UDDI is to establish standards for e-commerce; UDDI is a web-based, distributed, Web service-provided implementation standard specification for information registries, and also contains a set of Web service that enables enterprises to provide themselves Register to enable other businesses to discover the implementation criteria for the Access Protocol.

v. History of WEB Service development

Java API for xml-based Web Service

Vi. creation of WebService
    • 1. Create a WebService Project
    • 2. Create a Service Java class
    • 3. Create WebService
    • 4. Add JAX-WS supported JAR packages
    • 5. Publish WebService works and publish Web projects as
    • 6. Access http://localhost:8080/PB_WebService/CalculatorPort?wsdl via URL
Create a service-side webservice

Java class

 PackageCom.pb.service;/*** A simple calculator class **/ Public classCalculator {//addition     Public intAddintNUM1,intnum2) {        returnnum1+num2; }    //Subtraction     Public intSubintNUM1,intnum2) {        returnNum1-num2; }    //Good Way     Public intMulintNUM1,intnum2) {        returnNum1*num2; }    //Division     Public intDivintNUM1,intnum2) {        returnnum1/num2; }    //Mold Removal     Public intMoDintNUM1,intnum2) {        returnnum1%num2; }    }

WebService

 PackageCom.pb.service, @javax. Jws.webservice (targetnamespace= "http://service.pb.com/", ServiceName = "CalculatorService", PortName = "Calculatorport") Public classcalculatordelegate {com.pb.service.Calculator Calculator=NewCom.pb.service.Calculator ();  Public intAddintNUM1,intnum2) {        returnCalculator.add (NUM1, num2); }     Public intSubintNUM1,intnum2) {        returncalculator.sub (NUM1, num2); }     Public intMulintNUM1,intnum2) {        returnCalculator.mul (NUM1, num2); }     Public intDivintNUM1,intnum2) {        returnCalculator.div (NUM1, num2); }     Public intMoDintNUM1,intnum2) {        returnCalculator.mod (NUM1, num2); }}

Xml

<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xmlns:web= "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi: schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version= " 3.0 "> <display-name></display-name> <servlet> <description>jax-ws endpoint-calculators Ervice</description> <display-name>CalculatorService</display-name> <servlet-name>calcul Atorservice</servlet-name> <servlet-class>Com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-nam E>calculatorservice</servlet-name> <url-pattern>/CalculatorPort</url-pattern> </ servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </ Welcome-file-list> <listener> <listener-class>Com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class> </listener></web-app>

Release Tomcat on

Access via HTTP://LOCALHOST:8080/PB_WEBSERVICE/CALCULATORPORT?WSDL

Results

Description success

Create client

Create a Java Project

Create a Web Service Client

Test class

   package   com.pb.client.test;   Import   com.pb.service.CalculatorDelegate;   Import   Com.pb.service.CalculatorService;   Public   class   webserviceclienttest {  public   static   void   main (string[] args) { //  Get service instance  calculatorservice service=  new   Calculato        Rservice ();                 //  get the proxy class interface for the service  calculatordelegate cd=  service.getcalculatorport ();         //  Call method  System.out.println ("and:" +cd.add (3 ));        System.out.println ( "Difference:" +cd.sub (3 ));        System.out.println ( "Product:" +cd.mul (3 ));        System.out.println ( "quotient:" +cd.div (3 ));    System.out.println ( "modulo:" +cd.mod (3 )); }}
Seven, Apache CXF

Viii. creating HelloWorld with CXF

1. Create a new Java project

2. Importing the JAR Package

3. Create WebService interface such as: Helloworldservcie

4. Create an implementation class for the interface Helloworldserviceimpl

5.

6.

Interface

 Package Com.pb.service; /**  */Publicinterface  helloworldservice        { /**     * Method of speaking * * public     void  SayHello (String name);}

Implementation class

 Package Com.pb.service.impl; Import Com.pb.service.HelloWorldService; /**  */Publicclassimplements  HelloWorldService {    @ Override    publicvoid  SayHello (String name) {                SYSTEM.OUT.PRINTLN (name + "  say     HelloWorld!!!" );    }}

Service class

 PackageCom.pb.webservice;ImportOrg.apache.cxf.frontend.ServerFactoryBean;ImportCom.pb.service.HelloWorldService;ImportCom.pb.service.impl.HelloWorldServiceImpl; Public classWebService {/*** Release WebService*/     Public Static voidMain (string[] args) {//Serverfactorybean ObjectServerfactorybean bean=NewServerfactorybean (); //creating an interface instance ObjectHelloWorldService hello=NewHelloworldserviceimpl (); //Set the service typeBean.setserviceclass (HelloWorldService.class); //set the publishing address byhttp://localhost: 8080/helloworld?wsdl Authenticated accessBean.setaddress ("Http://localhost:8080/helloWorld"); //set the class for the entity serviceBean.setservicebean (hello); //Publishbean.create (); }}

Client

 Packagecom.pb.client;ImportOrg.apache.cxf.frontend.ClientProxyFactoryBean;ImportCom.pb.service.HelloWorldService;/*** Client*/ Public classClientService { Public Static voidMain (string[] args) {//Agent Factory BeanClientproxyfactorybean bean=NewClientproxyfactorybean (); //set TypeBean.setserviceclass (HelloWorldService.class); //Set up service addressBean.setaddress ("Http://localhost:8080/helloWorld"); //Create a Service object instanceHelloWorldService service=(HelloWorldService) bean.create (); //Calling MethodsService.sayhello ("Zhang San"); }}
IX, and spring integration

Client

WebService Study Summary

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.