"Dark Horse Android" (WebService) concept/Call/WSDL interface

Source: Internet
Author: User
Tags dateformat soap

The concept of WebService

WebService is an application that provides a Web -accessible API.

Resolve remote calls between two systems or (applications) ... ..

Calls are cross-lingual, cross-platform ...

WebService the most basic component is the client, the service side ...

Myserversocket.java

package Cn.itcast.server;import Java.io.ioexception;import Java.io.inputstream;import Java.net.ServerSocket;import  java.net.socket;/** * * Start Server * @ author [email protected] * */public class myServerSocket {/** * @param args * @throws IOException */public static void Main (string[] args) throws IOException {ServerSocket serversocket=new serversocket (8080 ); while (true) {Socket socket=serversocket.accept (); InputStream is=socket.getinputstream (); byte b []=new byte [1024]; int length=0; StringBuffer buffer=new StringBuffer (); while ((Length=is.read (b))!=-1) {string String=new string (b,0,length); Buffer.append (string);} System.out.println (Buffer.tostring ());}}} 

Server:( as a server, how to publish your own application into a WebService, let others call )

XML (the data format passed when the client interacts with the server WebService )

WebService Description Language(Web Service Description Language : API)XML, referred to as WSDL

Soap(Simple Object Access Protocol) WebService protocol for clients interacting with the server

(Soap two versions (SOAP 1.1 and soap1.2)), the current version is soap1.1, because Java JDK only support soap1.1 version of the protocol release ..

Soap protocol = transmits XML- formatted data on top of http :

Publish service:

Java JDK provides a self-brought class to publish Java applications as WebService

/**

* 1, provide service to external access address

* 2, the object that provides the class of service ...

*/

Endpoint.publish ("Http://192.168.9.100:9999/helloService", New HelloService ());

Note:1,endpoint is a java JDK - provided class for publishing WebService, so your jdk The version must be above 1.6.0_21.

2, the published class must contain a method that is valid (the method must be a non-static, non- final method of publish )

3, the published class must have annotations ...

Package Cn.itcast.server;import Javax.xml.ws.endpoint;public class Publishserver {/** * @param args */public static void M Ain (string[] args) {//java JDK provides a self-brought class that can publish Java applications to WebService/** * 1, providing services to external access address * 2, providing services to objects of the class ... */endpoint.publish ( "Http://192.168.9.100:9999/helloService", New HelloService ());}}
Instructions

Helloservice.java

package Cn.itcast.server;import Java.text.dateformat;import Java.text.simpledateformat;import Java.util.Date;import Javax.jws.webmethod;import Javax.jws.webparam;import Javax.jws.webresult;import Javax.jws.WebService;import Cn.itcast.bean.User, @WebService (targetnamespace= "www.baidu.com", servicename= "Helloserviceporttype", portname= " Serviceporttype ") public class HelloService {@WebMethod (exclude=true) public void Doublekill () {System.out.println (" Itcast ");} Public@webresult (name= "date") string GetDate (@WebParam (name= "date") string date) {DateFormat dateformat=new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); return Dateformat.format (New Date ()); @WebMethod (operationname= "Getuserbyname") public User Getuserbyid (int id) {User user=new User (); User.setid (ID); User.setmomo ("18078900982"), User.setusername ("Lao Feng"), User.setweibo ("[email protected]"); User.setweixin (" l89999 "); return user;}} 
WebService client-side invocation

Client:

( as a client, how to call someone else's published WebService)

Invoke Service: We can generate a local wsimport based on the server specification (wsdl) by A command that comes with the Java JDK . Java Code

We directly manipulate these Java Code, we can call WebService

Wsimport-d. + The address of the service manual (wsdl) to generate the local class file

Wsimport-s. +The address of the service manual (wsdl) generates the local class file with the Java file

Wsimport-s. -P ( package name ) + service manual (wsdl) address to generate a local class file with Java file

Wsimport-s. +The address of the service manual (wsdl) generates the local class file with the Java file

The first method of invocation.

The second method calls WebService

The first way to invoke: by Wsimport

Tool 1:WebService Explorer(call WebService via graphical interface )

Tool 2:TCP/IP Monitor can intercept WebService clients and WebService the entire process of interacting with the server and the format of the data transfer .

The second method of invocation : A class urlconnect that comes with the Java JDK ( You can send an http Request )

Principle: We can send an http request to the WebService server by urlconnect this object. XML -formatted data,

Simulates the soap protocol , because the soap protocol is the transfer of XML based on http formatted data :

Summary of the third invocation of WebService

Third Way call: Call WebService via client programming We need the class Service that comes with the java jdk , and We need to rely on an interface that we can get from the native code generated by wsimport ...

/**

There are a lot of free services on the Internet , http://www.webxml.com.cn can be found on this website.

**/

WebService Calling services on the Internet

1, call on the Internet mobile phone number attribution to query the service

Use the first:wsimport generate local code calls

Use the second: use urlconnect to invoke the weather forecast .

The fourth method of invocation: calling WebService via Ajax

XMLHttpRequest Object when the browser comes with an object, you can send an HTTP request through this object , transfer XML - formatted data to the server

(Simulate soap protocol ... )

Unreachable: Cross-domain (a site- js access to b - site requests ...)

A detailed description of the WSDL service

WebService deepening :

The process of monitoring WebService requests through TCP Ip/monitor through several calls to the WebService client and server

Intercept the requested data, analyze the data ...

When the WebService client interacts with the server,

First service specification for wsdl via get request

The second time via post request WebService service ...

WebServicethe summary

Understand the description of the WSDL service:

We can modify The description of the WSDL service specification by modifying the annotations.

If you modify the manual, the local code generated by Wsimport will be affected ....

Extension: How to make a Web player

Three different ways:

The first way: the window Media Player is transferred through JS

The second way:adobefalsh There is a language ActionScript can operate hardware: camera, microphone, speaker ...

Major browsers to support Adobefalsh ,adobeflash inside the ActionScript to JS provides an interface,JS can be ActionScript

Some features to finish playing ...

The third way: through the HTML5 to complete the production of the player.


"Dark Horse Android" (WebService) concept/Call/WSDL interface

Related Article

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.