Get the App
SLTechnology News&Howtos  ›  Development  › 

How to call the .asmx interface of webservice by Java

Shulou Source: shulou.com Published: 2022-06-03 16:39:11 11月14日 Update

This article will explain in detail how Java calls the.asmx interface of webservice. The content of the article is of high quality, so Xiaobian shares it with you as a reference. I hope you have a certain understanding of related knowledge after reading this article.

preface

Contact a webservice interface ending in.asmx and decide to write it down for memory gain.

I. Interface type

interfaces terminated with.asmx

Example: Interface address: http://IP address/xxx/service/xxx/xxxx.asmx Method Name: Test Parameter type: string II. Use Step 1. Access method

The code is (example):

Controller class:

String s = clientUtil.test("http://IP address/xxx/service/xxx/xxxx.asmx", "test","test");

Call class:

public static String test(String Url, String methodName, String str) throws Exception { String ref = null; // webService link address String url = Url; //Get the domain name address defined by server String soapaction = "http://tempuri.org/"; Service service = new Service(); try { Call call = (Call) service.createCall(); call.setTargetEndpointAddress(url); //Set which method to call call.setOperationName(new QName(soapaction, methodName)); //Set parameter name to pass call.addParameter(new QName(soapaction,"str"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); //provide standard type addParameter must have setReturnType call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING); call.setUseSOAPAction(true); call.setSOAPActionURI(soapaction + methodName); //Call method and pass parameters ref = (String) call.invoke(new Object[]{str}); return ref; } catch (Exception e) { e.printStackTrace(); } return ref; }2. Imported maven

As follows:

javax.activation activation 1.1.1 org.apache.axis axis 1.4 axis axis-jaxrpc 1.4 About Java how to call the webservice.asmx interface to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Tags: Interface address parameter method type content article more knowledge article good code preface domain name method standard step example memory quality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno Apple Microsoft MariaDB