透過度娘等方式,個人理解為變相的soap協定加xml工單一處理,
/wsdl www.webxml.com.cn/webservices…
造訪查看然後找到下圖中定義的內容:注意使用關聯key找到對應的必要使用的參數。 maven 使用axis應用依賴(不可缺少必須)<!-- https://mvnrepository.com/artifact/org.apache.axis/axis --> <dependency> <groupId>org.apache.axis</groupId> <artifactId>axis</artifactId> <version>1.4</version> </dependency> <!-- https://mvnrepository.com/artifact/wsdl4j/wsdl4j --> <dependency> <groupId>wsdl4j</groupId> <artifactId>wsdl4j</artifactId> <version>1.6.2</version> </dependency> <!-- 解决cell 转换问题--> <!-- https://mvnrepository.com/artifact/javax.xml/jaxrpc-api --> <dependency> <groupId>javax.xml</groupId> <artifactId>jaxrpc-api</artifactId> <version>1.1</version> </dependency> <!-- 解析调用结果以及数据转换包--> <!-- https://mvnrepository.com/artifact/commons-discovery/commons-discovery --> <dependency> <groupId>commons-discovery</groupId> <artifactId>commons-discovery</artifactId> <version>0.2</version> </dependency>
@Test public void testWebService() { try { //wsdl地址 String endpoint = "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx"; //命名空间 String namespace = "http://WebXml.com.cn/"; //服务名 String serviceName = "qqOnlineWebService"; //方法名 String methodName = "qqCheckOnline"; //soapAction 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); //启用soap call.setUseSOAPAction(true); //设置soapAction 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); } }
以上是SpringBoot如何使用axis呼叫webservice介面的詳細內容。更多資訊請關注PHP中文網其他相關文章!