WebService
Definition

Personal understanding
Through Du Niang and other methods, my personal understanding is that it is a disguised soap protocol plus xml process Single processing,
Practice
webservice common sense
A webservice interface publishing address is often similar:
www.webxml.com.cn/webservices…
emailEmail address interface: www.webxml.com.cn/WebServices…
National weather conditions interface:
www.webxml.com.cn/WebServices…
qq Take the online interface verification interface as an example
Add after the interface:/wsdl www.webxml.com.cn/webservices…
Access and view and find the one defined in the figure below Content: Pay attention to using the associated key to find the corresponding necessary parameters.

maven uses axis
Apply dependencies (cannot be missing and required)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
< dependency >
< groupId >org.apache.axis</ groupId >
< artifactId >axis</ artifactId >
< version >1.4</ version >
</ dependency >
< dependency >
< groupId >wsdl4j</ groupId >
< artifactId >wsdl4j</ artifactId >
< version >1.6.2</ version >
</ dependency >
< dependency >
< groupId >javax.xml</ groupId >
< artifactId >jaxrpc-api</ artifactId >
< version >1.1</ version >
</ dependency >
< dependency >
< groupId >commons-discovery</ groupId >
< artifactId >commons-discovery</ artifactId >
< version >0.2</ version >
</ dependency >
|
Copy after login
Code (paste available)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | @Test
public void testWebService() {
try {
String endpoint = "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx" ;
String namespace = "http://WebXml.com.cn/" ;
String serviceName = "qqOnlineWebService" ;
String methodName = "qqCheckOnline" ;
String soapAction = "http://WebXml.com.cn/qqCheckOnline" ;
Service service = new Service();
Call call = (Call) service.createCall();
call.setTimeout( 3000 );
call.setTargetEndpointAddress( new java.net.URL(endpoint));
call.setOperationName( new QName(namespace, methodName));
call.addParameter( new QName(namespace, "qqCode" )
, org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.setReturnType(XMLType.XSD_SCHEMA);
call.setUseSOAPAction( true );
call.setSOAPActionURI(soapAction);
SOAPService soapService = new SOAPService();
soapService.setName(serviceName);
call.setSOAPService(soapService);
Schema result = (Schema) call.invoke( new Object[]{ "xxxxx" });
for ( int i = 0 ; i < result.get_any().length; i++) {
System.out.println(result.get_any()[i]);
}
} catch (Exception e) {
log.error( "ddd" , e);
}
}
|
Copy after login
Regarding the above code, let me complain here. There are actually many examples of this on the Internet, but problems will occur when actually calling it. Note:


##xxxx needs to fill in the real QQ number
The above is the detailed content of How SpringBoot uses axis to call the webservice interface. For more information, please follow other related articles on the PHP Chinese website!