Preface: WebService first acquaintance, only see one out of 10,000 fur, please expert advice.
1, what is WebService
Baidu Encyclopedia explains this:
WEB Services is an online application service published by an enterprise that completes its specific business needs, and other companies or applications can access and use the online service over the Internet.
It is a universal model for building applications that can be run in any operating system that supports network traffic; It is a new branch of Webwebservice application that is self-contained, self-describing, modular, and can be published, positioned, and invoked via the Web. A Web service is an application component that logically provides data and services to other applications. Each application accesses the Web service through a network protocol and some standard data formats (HTTP,XML,SOAP), via the web The internal execution of the service gets the desired results. WEB Service can perform any function from simple requests to complex business processes. Once deployed, other Web service applications can discover and invoke the services that it deploys.
WEB services in simple words, is the system external interface.
2. SOAP (Simple Object Access Protocol)------in XML (like WSDL) using annotations: Add @webservice on an interface---indicate that this is a WebService service interface
Implement and publish the WebService interface, client access:
HTTP://LOCALHOST:8080/SNS?WSDL---This is the passed XML message
XML Analysis:
Types: The type used to define access
Messages:soap (the number of information is twice times or more of the service)
ProtoType: Indicates the interface of the server, specifying in and out messages via operation
Operation->input: parameters (Input message)
Operation->output: Return value (Output message)
Binding: The format used for binding message passing (input/output)
Service: Specifies the name published by the services
A common tool for WebService:
Tcpmon set up listening <request response>messages
Setting up listening ports simulate client Access server procedures: Client <------>tcpmon (forwarding/return information) <------> Server
3. Publish, invoke and compile packaged WebService services:
(1), server-side publishing services:<---------interface that services
public class TestServer {
/**
* @param args
*/
public static void Main (string[] args) {
String address= "Http://localhost:8080/sns";
Endpoint.publish (Address, New Myserviceimpl ());//Interface Implementation class
}
}
(2), client display results:<----------Invoke service
public class TestClient {
/**
* @param args
* @throws malformedurlexception
*/
public static void Main (string[] args) throws Malformedurlexception {
Myserviceimplservice msis=new Myserviceimplservice ();
Imyservice Ims=msis.getmyserviceimplport ();
System.out.println (Ims.minus (40, 20));
System.out.println (Ims.add (40, 20));
System.out.println ("Find a root dir printinto console:wsimport-d d:temp/webservice/-keep-verbose http://localhost:808 0/sns?wsdl ");
}
}
(3), packaging to generate the source file and the detailed information after the compilation
CMD: First find the root directory D: input wsimport-d d:temp/webservice/-keep-verbose http://localhost:8080/sns?wsdl
4, code first or contract priority.
(1), Code first (focus on development efficiency)------directly to implement the application of code
JWS also supports Web services development using code first, contract compilation methods. JWS encourages code-first methods so that WSDL documents can be easily generated.
Once the service is released, the corresponding WSDL document is created and the client can develop it accordingly. In the Java language, through annotations, programmers
You can decide how to generate WSDL documents, or generate WSDL-related artifacts in turn, under certain special requirements.
Code First Instance: http://book.51cto.com/art/200911/163800.htm
(2), contract first (pay attention to development standards)------suitable for heterogeneous systems
Define the layer of the contract:
UI layer: Includes interface, validation logic, and interaction between user controls
Logical layers: Implementing requirements, business rules, computing, and reporting generation
Database layer: Storing data and guaranteeing referential integrity between tables
(Note: Logical modules are separate from database storage)
To define a service for a contract:
What results can be obtained from the service, what methods the service has, and what data structures are required for the parameters of these methods.
Contract Priority principle: http://book.51cto.com/art/201111/301309.htm
Contract Priority Example: http://blog.ziki.cn/349.html
Personal subjective view: Contract priority is the most people want to see the results but the actual development is more focus on efficiency and cost, so the real example of code priority in reality.
5, view the WSDL interface and parameters
You can open the WebService Explorer under Eclipse Java EE to view the services of the WSDL access, including interfaces and parameters
URL:HTTP://LOCALHOST:8080/SNS?WSDL