Call the webService interface according to the access path and domain name

If the customer does not provide the wsdl file and does not provide a direct access link, such as directly visiting a page to tell how to call the modified interface, you can

 

According to the description of the document, you can write the relevant calling method, configure the calling method, configure the passing parameters, and you can also complete the webService interface.

 

Compared with the direct generation of the client based on wsdl, it is a little troublesome to write, and it is a little troublesome to set relevant parameters and other information. But if

 

When encountering such an interface document, it is still necessary to write it in this way.

 

Test access domain name: http://www.webxml.com.cn/WebServices/WeatherWebService.asmx

 

import java.util.Vector;

 

import javax.xml.namespace.QName;

 

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

 

public class Main {

           public static void main(String[] args) {

              System.out.println("-----------------------------------Step Start");

             // the address of the interface

             String url = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx";

 

             // domain name

             String soapaction = "http://WebXml.com.cn/";

             String City = "Beijing";

 

             Service service = new Service();

 

             try {

 

                          Call call = (Call) service.createCall();

 

                          call.setTargetEndpointAddress(url);

 

                          // set which method to call

                          call.setOperationName(new QName(soapaction, "getWeatherbyCityName"));

 

                          // set the parameters to be passed

                          call.addParameter(new QName(soapaction, "theCityName"),                                                                       org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);

 

                          // data type to return (custom type)

                          call.setReturnType(new QName(soapaction, "getWeatherbyCityName"), Vector.class);

                          call.setUseSOAPAction(true);

                          call.setSOAPActionURI(soapaction + "getWeatherbyCityName");

 

                          Vector v = (Vector) call.invoke(new Object[] { City });// call the method and pass parameters

 

                          for (int i = 0; i < v.size(); i++) {

 

                                                    System.out.println(v.get(i));

                          }

 

                          } catch (Exception ex) {

                               ex.printStackTrace();

                          }

                          System.out.println("-----------------------------------End of step");

                          }

}

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326914190&siteId=291194637