Web Service (top)

Source: Internet
Author: User
Tags soap xml parser wsdl

1.XML

CDATA refers to text data that should not be parsed by the XML parser.
In the XML element, < and & is illegal. The parser interprets the character < as the beginning of the new element and interprets the character & as the beginning of the character entity.
Some text, such as JavaScript code, contains lots < or & characters. To avoid errors, you can define the script code as CDATA.
CDATA Part by <![CDATA[ start, by ]]> end.


A DTD (document type definition) is an XML constraint that is designed to constrain the way XML tags are written.
The XML Schema (XML Schema Definition,xsd) is more constrained than the DTD, so the DTD is being phased out.
Import DTD files through eclipse in development for easy development tips.

Importing DTDs in XML can be done in two ways:

    1. Written directly in the XML <!DOCTYPE 根节点 [ ...... ]> .
    2. Written in a specialized DTD file, and then import the DTD file in XML through a specific statement. When importing, know if the DTD file is a local file or a shared file.
      Import format for local file: <!DOCTYPE 根节点 SYSTEM "dtd的URL"> .
      Import format for shared files: <!DOCTYPE 根节点 PUBLIC "dtd的名称""dtd的URL"> .

Book.xsd

<?xmlVersion= "1.0" encoding= "UTF-8"?><schemaxmlns="Http://www.w3.org/2001/XMLSchema"targetnamespace="Http://www.atguigu.com/bookSchema"elementformdefault="qualified">    <elementname="Bookshelf">        <complexType>            <sequencemaxoccurs="unbounded">                <elementname="book">                    <complexType>                        <sequence>                            <elementname="title"type="string" />                            <elementname="Author"type="string" />                            <elementname="Price"type="string" />                        </sequence>                    </complexType>                </element>            </sequence>        </complexType>    </element></schema>

Book.xsd file by xmlns="http://www.w3.org/2001/XMLSchema" Introducing schema constraints.
targetNamespace="http://www.atguigu.com/bookSchema"Is the ID of the book.xsd file.

Book.xml

<?xml version="1.0" encoding="UTF-8"?><书架 xmlns="http://www.atguigu.com/bookSchema"    xmlns:dd="http://www.w3.org/2001/XMLSchema-instance"    dd:schemaLocation="http://www.atguigu.com/bookSchema book.xsd">    <书>        <书名>JavaScript开发</书名>        <作者>老佟</作者>        <售价>28.00元</售价>    </书></书架>

Book.xml introduces a constraint xmlns="http://www.atguigu.com/bookSchema" .
By schemaLocation="http://www.atguigu.com/bookSchema book.xsd" specifying the location of the constraint file. Attribute schemalocation is introduced through constraints, xmlns="http://www.w3.org/2001/XMLSchema-instance" so there are two constraints introduced here, which requires the alias of one of the constraints (since the DTD cannot solve the problem of "tagging with the same name, resulting in naming conflicts when multiple constraints are introduced", so there is a schema, It is a substitute for a DTD). The DD in the code below is the alias.

xmlns:dd="http://www.w3.org/2001/XMLSchema-instance" dd:schemaLocation="http://www.atguigu.com/bookSchema book.xsd"
2.WebService Introduction

Web Service
A WEB service is an application component that communicates using open protocols and can be discovered by using UDDI.
Web service is based on HTTP and XML. The HTTP protocol is the most commonly used Internet protocol. XML provides a language that can be used between different platforms and programming languages.
Elements of the WEB services platform:

    • SOAP (Simple Object Access Protocol)
    • UDDI (general description, Discovery, and integration)
    • WSDL (Web Services Description Language)

Soap
Soap refers to the Simple Object Access Protocol, which is a protocol for communication between applications.
SOAP is XML-based, platform-independent, language-independent.
Soap is simple and extensible.
SOAP allows you to bypass the firewall.
SOAP will be developed as a standard for the industry.

Wsdl
WSDL refers to the Network Service Description Language (Web Services Description Language).
WSDL is a document written using XML. This document can describe a WEB service. It can specify the location of the service and the operation (or method) provided by the service.

3. Developing a Web service using the JDK

Publishing a Web Service

import javax.jws.WebMethod;import javax.jws.WebService;/* * SEI:  */@WebServicepublicinterface HelloWS {    @WebMethod    publicsayHello(String name);}
import javax.jws.WebService;  /*   * SEI implementation   */  @WebService  public  class  Hellowsimpl implements  hellows { @Override  public< /span> string sayhello  (string name) {System.. println         ( "server SayHello ()"  +name); return      "Hello"  + name; }}
import javax.xml.ws.Endpoint;import com.atguigu.day01_ws.ws.HelloWSImpl;/* * 发布Web Service */publicclass ServerTest {    publicstaticvoidmain(String[] args) {        "http://192.168.1.108:8989/day01_ws/hellows";        Endpoint.publishnewHelloWSImpl());        System.out.println("发布webservice成功!");    }}

Requesting a Web Service
Generates client code based on the WSDL document.

import Com.atguigu.day01_ws.ws.HelloWSImpl;import Com.atguigu.day01_ws.ws.HelloWSImplService;/** Call WebService */ Public classclienttest { Public Static void Main(string[] args) {Hellowsimplservice factory =New Hellowsimplservice(); Hellowsimpl hellows = Factory.Gethellowsimplport(); System. out.println(Hellows.GetClass()); String result = Hellows.SayHello("Jack"); System. out.println("Client"+result); }}

Web Service (top)

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.