Steps for java to invoke the. asmx interface of webservice

  • 2021-11-13 01:33:48
  • OfStack

Directory Preface 1. Interface Type 2. Use Step 1. Access Mode 2. Imported maven

Preface

Contact 1. asmx ending webservice interface, in order to increase memory decision recorded.

1. Interface type

Interface terminated with. asmx


 Example: Interface address: http://IP Address /xxx/service/xxx/xxxx.asmx
	 Method name: test
	 Parameter type: string 

2. Use steps

1. Access method

The code is as follows (example):

Class controller:


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

Invoke 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, server Defined 
        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 the parameter name to pass 
           call.addParameter(new QName(soapaction,"str"),org.apache.axis.encoding.XMLType.XSD_STRING,
       javax.xml.rpc.ParameterMode.IN);
            //  Provide standard types   Have addParameter You have to have setReturnType
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
            call.setUseSOAPAction(true);
            call.setSOAPActionURI(soapaction + methodName);
            //  Calling methods and passing parameters 
			ref = (String) call.invoke(new Object[]{str});
           return ref;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ref;
    }

2. Imported maven

As follows:


<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
</dependency>
<dependency>
    <groupId>org.apache.axis</groupId>
    <artifactId>axis</artifactId>
    <version>1.4</version>
</dependency>
<dependency>
    <groupId>axis</groupId>
    <artifactId>axis-jaxrpc</artifactId>
    <version>1.4</version>
</dependency>

Reference:
[1]https://blog.csdn.net/qq_34302802/article/details/101197464


Related articles: