<dependency> <groupId>axis</groupId> <artifactId>axis</artifactId> <version>1.4</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>axis</groupId> <artifactId>axis-ant</artifactId> <version>1.4</version> <type>jar</type> <scope>compile</scope> </dependency>
只需要引入2个asix包
import java.rmi.RemoteException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.encoding.XMLType;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.junit.Test;
public class PropertiesTest {
@Test
public void testCXF() {
try {
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress("http://192.168.0.96:8080/ws/tdcf?wsdl");
//QName构造方法参数1填写namespace(从xml找)参数2填写方法名
QName qName = new QName("http://service.ws.tdcf.com/", "login");
call.setOperationName(qName);
call.setUseSOAPAction(true);
//以下是添加参数,方法名中有参数,就需要在下面添加
call.addParameter("code", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("pwd", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("ip", XMLType.XSD_STRING, ParameterMode.IN);
//设定返回值类型
call.setReturnType(XMLType.SOAP_STRING);
//接收返回值
Object result = call.invoke(new Object[] { "admin","777777", "192.168.0.96" });
System.out.println(result);
} catch (RemoteException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
}
}