In the previous article, I introduced you to a detailed explanation of the WebService tutorial (I)
Reasons to use tools:
1. Use tools to better understand the process of WebService requests
2. Use the tool WsExplore to obtain the format of SOAP data transmission and reception.
3. Use the tool Tcp/Ip Monitor to monitor the specific data of the interceptor request header and response header
What is SOAP?
SOAP is a text protocol based on XML encoding specification. Simply put, SOAP is to transmit XML data on HTTP to realize remote calls [no matter what language your server is written in, as long as you receive XML data of the SOAP protocol and return XML data of the SOAP protocol, it can be called by any language]
Using WsExplorer instance: Verify that QQ is online
When using qqCheckOnLine verification in qqOnlineWebServiceSoap, the returned is
qqCheckOnlineResponse
qqCheckOnlineResult (string): N
Click source to see the detailed information, the information is as follows:
1: This is the message format:
The code copy is as follows:
http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://WebXml.com.cn/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-
-
870931520
2: The following is the received XML format
The code copy is as follows:
http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-
- http://WebXml.com.cn/">
N
When using qqOnlineWebServiceHttpGet or qqOnlineWebServiceHttpPost, the returned ones are all
Nhttp://WebXml.com.cn/">N>
Using Tcp/Ip Monitor
TCP/IP Monitor can not only see SOAP data, but also obtain header information for HTTP requests and receptions.
1. Location: This tool is located at: window>show view>other>MyEclipse Common (common tools)>TCP/IP Monitor
2. This tool is equivalent to an agent. After startup, it will listen for a local port and then forward the request to the specified target IP and port.
After obtaining the data, return the data to the customer intact. In the eyes of customers, this agent should always be the first to access, otherwise we will not see the process of data transmission.
3. Configuration options:
On the open TCP/IP Monitor interface: view Menu (small arrow in the upper right direction)>Properties>Add (add on the right)
Set to the following properties:
first step:
1) local monitoring port (listen to the local port number): 9876, set a 4-bit port number at will, and will be accessed in the form of http://127.0.0.1:9876
2) Host name (the server to be listened to, such as www.VeVB.COM): 127.0.0.1 Because the machine publishes a WebService, it monitors the native IP. It can also be any host.
3) Port (port of the target server to be listened to): 6666 - Because the WebService we published is http://127.0.0.1:6666/helloworld, 6666 is the port number that needs to be listened to.
4) Type (the type of listening):
-- TCP/IP: The original address will be used to continue accessing the next request, such as user input: http://127.0.0.1:9876/helloworld?wsdl will return to the wsdl service access address as before.
-- HTTP: The destination address will continue to access the next request. As user input: http://127.0.0.1:9876/helloworld?wsdl will use http://127.0.0.1:6666/helloworld to access the sayHi method when requesting the method. This method will no longer be proxyed. Because it is no longer the port number being listened to.
At the listening type, I selected TCP/IP, and then checked the change of the address in the returned wsdl file by entering: http://127.0.0.1:9876/helloworld?wsdl in the address bar.
time out: Set the connection time when access is unsuccessful, and keep it to 0, that is, it is not set.
After setting it, click the OK button, and then click the Start button on the right, and the monitoring has started.
Step 2:
Configure the WSDL URL on the MyEclipse WebService to: http://127.0.0.1:9876/helloworld?wsdl, note that the port of MyEclipse TCP/IP Monitor is used. Instead of directly visiting the http://127.0.0.1:6666/helloworld?wsdl published
How to modify the content of wsdl file?
Use WebService's annotations.
1. @WebService-Definition Service
2. @WebMethod-Definition Method
3. @WebResult-Definition Return Value
4. @WebParam-Define Parameters
Note: Different versions support different levels of comments:
1. 1.5 is not supported.
2. Versions before 1.6.0_20 must use complete annotations.
3. After 1.6.0_21, you can only use @WebService to annotate the class.
The function of comments:
Through the comments of WebService, you can describe the Web service more vividly. This generates a WSDL document.
When the WebService annotation is modified, the code generated by the client will also affect.
The method and parameter names of the called also changed.
Example:
@WebService(name="myName",//corresponding portType name="myName" portName="myPort", //corresponding port name="myPort" serviceName="myService",//corresponding service name="myService" targetNamespace="http://leaf.com/mynamespace")//can write package public class HelloWorld{ private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @WebMethod(action="myAction",//Define a soapAction="myAction" to find this method to execute operationName="myOperationName")//Define the method that can be called, and a specific method of the corresponding class will be generated, operation name=".." public @WebResult(name="mySayHelloResult")String//Define the name of the return value saysHello(){ return "HelloWorld"; } @WebMethod(action="mySayHiAction",operationName="mySayHiOperationName") public @WebResult(name="mySayHiResult")String saysHi(@WebParam(name="myParaName", //Put the parameters into the header information to protect the parameters. By default, header=true, mode=Mode.IN) String name){ String str = "Hello: "+name+", the current time is: "+sdf.format(new Date()); return str; } public static void main(String[] args) { Endpoint.publish("http://127.0.0.1:6666/helloworld",new HelloWorld()); } }3: After the above program is released to the public, we access it through MyEclipse's WebService Explorer
You will find a different prompt message than before, but in fact, the same method is still called.
4: Use wsimport s again. http://127.0.0.1:6666/helloworld?wsdl to generate java code and then call the following is the calling code (it can be described as unrecognizable, but the same work is done.)
package com.leaf.mynamespace; public class Main { public static void main(String[] args) { //By analyzing wsdl, we can see that calling getMyPort from myService returns myName MyName myName = new MyService().getMyPort(); //Call the sayHi method through mySayHiOperationName of myName String str = myName.mySayHiOperationName("Wang Jian"); System.err.println(str); } }Detailed explanation of the WebService tutorial (II) Let me introduce it to you here first, I hope it will be helpful to you!