Detailed WebService (2)

The WsExplorer and Tcp/Ip Monitor tools themselves exist in eclipse and MyEclipse. 
Reasons for using the tools: 
1. Use the tool to better understand the process of WebService requests 
2. Use the tool WsExplore to obtain the format of SOAP data sending and receiving 
3. Use The tool Tcp/Ip Monitor can 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 the basis of HTTP to realize remote invocation [no matter what language your server is written in, as long as it receives the XML data of the SOAP protocol, And return the XML data of the SOAP protocol, it can be called by any language] 
Use WsExplorer instance: verify whether qq is online 
and use qqCheckOnLine verification in qqOnlineWebServiceSoap, the returned is 
qqCheckOnlineResponse  
    qqCheckOnlineResult (string): N   Click source to see detailed information, information As follows:  1: This is the format of the sent message:  <soapenv:Envelope xmlns:soapenv=" 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"> 
- <soapenv:Body> 
- <q0:qqCheckOnline> 
  <q0:qqCode>870931520</q0:qqCode>  
  </q0:qqCheckOnline> 
  </soapenv:Body> 
  </soapenv:Envelope> 
2:以下是接收到的XML格式 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
- <soap:Body> 
- <qqCheckOnlineResponse xmlns="http://WebXml.com.cn/"> 
  <qqCheckOnlineResult>N</qqCheckOnlineResult>  
  </qqCheckOnlineResponse> 
  </soap:Body> 
  </soap:Envelope>  When qqCheckOnline in qqOnlineWebServiceHttpGet or qqOnlineWebServiceHttpPost is used for verification, all returned are  <?xml version="1.0" encoding="utf-8"?>  <string xmlns =" http://WebXml.com.cn/">N</string Using Tcp/Ip Monitor  TCP/IP Monitor can not only see SOAP data, but also get HTTP request and received header information. 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 monitor a local port, and then Forward the request to the specified destination IP and port. After the data is obtained, the data is returned to the customer intact. From the client's point of view, this proxy should always be accessed first, otherwise we will not see the process of data transmission. 4. Configuration options:  On the open TCP/IP Monitor interface: view Menu (small down arrow at the top right)>Properties> 
 



 









Access in the form of  http://127.0.0.1:9876
2) host name (the server to be monitored, such as www.2cto.com ): 127.0.0.1 – because this machine publishes a WebService, it listens to this machine’s IP. It can also be any host. 
3) Port (the port of the target server to be monitored): 6666 - Because the WebService we published is http://127.0.0.1:6666/helloworld , 6666 is the port number that needs to be monitored. 
      4) Type (type of listening): 
-- TCP/IP: The original address will be used to continue to access the next request, such as user input: http://127.0.0.1:9876/helloworld?wsdl At this time, the wsdl service access address will be returned GR. 
-- HTTP : will continue to the next request using the target address. Such 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 way will no longer be proxied. Because it is no longer the port number being listened on.    In the listening type, I selected TCP/IP, and then by entering: http://127.0.0.1:9876/helloworld?wsdl in the address bar , check in the returned wsdl file: <soap:address location="http: ..."/> address changes. 

time out: Set the connection time for unsuccessful access, keep it as 0, that is, not set. 
After setting, click the OK button, and then click the Start button on the right, and the monitoring has been started. 
    Step 2: 
      Configure the WSDL URL on MyEclipse's WebService as: http://127.0.0.1:9876/helloworld?wsdl , note that the port of MyEclipse TCP/IP Monitor is used. Instead of directly visiting our published http://127.0.0.1:6666/helloworld?wsdl How to modify the content of the wsdl file? Use WebService annotations. 1. @WebService-defines services  2. @WebMethod-defines methods  3. @WebResult-defines return values  ​​4. @WebParam-defines parameters  Note: For annotations, different versions support different degrees:  1. 1.5 does not support.  2. Versions before 1.6.0_20 must use complete annotations.  3. After 1.6.0_21, you can only use @WebService to annotate classes.  The role of annotations:  Through WebService annotations, you can describe Web services more vividly. Thereby generating a WSDL document. When the WebService annotation is modified, it will also affect the code generated by the client. The method name and parameter names of the call have also changed. Example:  
 














 

@WebService(name="myName",//corresponding to portType name="myName" 
portName="myPort", //corresponding to port name="myPort" in the 
service serviceName="myService",//corresponding to service name="myService " 
targetNamespace=" http://leaf.com/mynamespace")//You can write packages similar to java at will 
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, which will generate the specific method of the corresponding class, operation name=".." 
public @WebResult(name="mySayHelloResult")String//Define the name of the return value 
sayHello(){ 
return "HelloWorld";  

@WebMethod(action="mySayHiAction",operationName="mySayHiOperationName") 
public @WebResult(name="mySayHiResult")String sayHi(@WebParam(name="myParaName", 
//Put the parameters in the header information to protect the parameters, by default 
                                                      header=true, 
  mode=Mode.IN in the body) 
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 outside world, we access it through MyEclipse's WebService Explorer and 
you will find a different prompt than before information, but in fact, it is still the same method that is called. 
4: Use wsimport –s again.  http://127.0.0.1:

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(); 
//through myName's mySayHiOperationName to call the sayHi method 
String str = myName.mySayHiOperationName("Wang Jian"); 
System.err.println(str); 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326484733&siteId=291194637