1。通过URL访问接口:
http://192.168.10.227/ebsService/services/ebsService?wsdl
2.找到方法名,地址
<operation name="sendAnnouncement">
<soap:address location="http://10.30.67.55:8085/service/Service.php"/>
3.下载2个jar
axis.jar,commons-discovery.jar
4.编写调用代码
package test;
import javax.xml.namespace.QName;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.jeecgframework.core.util.StringUtil;
public class JvsTest {
public static void main(String[] args) {
//String endpoint = "http://testweb.dev.php/testWebService/testWebService.php";//该段就是上面刚将的地址
Service service = new Service();
Call call;
//xml
String ggXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?><request><title></title></request>";
//指定类型
String namespace = "http://webserver.server.com/";
try {
call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
//接口名称
call.setOperationName(new QName(namespace, "sendAnnouncement"));
// // 此处需要配置传入参数类型与参数名称,如果未设置jax-ws则无法接受参数,会认为传入的参数为null <br>
//这里的参数名字必须为arg0,否则接受不到参数
call.addParameter("arg0",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
//多个参数
// call.addParameter("arg1",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
// call.addParameter("arg2",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
//参数
String param = new String(ggXML.getBytes(),"utf-8");//如果没有加这段,中文参数将会乱码
//放入参数
String s = (String) call.invoke(new Object[] {param});
//String s = (String) call.invoke(new Object[] {param,arg1,arg2});
s = new String(s.getBytes("ISO-8859-1"));//如果没有转换编码,中文也会乱码
//输出返回结果
System.out.println(s);
} catch (Exception e) {
e.printStackTrace();
}
}
}