1.我们需要三个组件 :http、 soap组件的cfx 、components 中的Java
htpp组件中设置端口号和IP地址这里不在讲解 在soap组件的cfx 设置如下:
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
/**
*
* @author liuli 服务实现类
*/
public class UISServiceImpl implements UISCXFWebService {
@Override
@WebMethod(operationName = "xcfWebservice")
public @WebResult(name = "String")
String xcfWebservice(@WebParam(name = "str1") String str1,
@WebParam(name = "str2") String str2,
@WebParam(name = "str3") String str3) {
String returnInfo = "你发送的参数:" + str1+"||"+ str2+"||"+ str3+"||";
System.out.println("=====返回报文=======" + returnInfo);
return returnInfo;
}
}
components 中的Java的设置
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
/**
*
* @author liuli 服务实现类
*/
public class UISServiceImpl implements UISCXFWebService {
@Override
@WebMethod(operationName = "xcfWebservice")
public @WebResult(name = "String")
String xcfWebservice(@WebParam(name = "str1") String str1,
@WebParam(name = "str2") String str2,
@WebParam(name = "str3") String str3) {
String returnInfo = "你发送的参数:" + str1+"||"+ str2+"||"+ str3+"||";
System.out.println("=====返回报文=======" + returnInfo);
return returnInfo;
}
}
===================================测试类=========================
import javax.xml.namespace.QName;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
public class CXFTest {
public static void main(String[] args) {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf
.createClient("http://localhost:8081/service/UISCXFWebService?wsdl");// wsdl地址
QName name = new QName("http://cxf/", "xcfWebservice");// 命名空间 ,方法名
Object[] objects = null;
try {
objects = client.invoke(name, "参数1", "参数2", "参数3");
} catch (Exception e) {
System.out.println(e);
}
// 调用web Service//输出调用结果
System.out.println(objects[0].toString());
}
}
=====================http://localhost:8081/service/UISCXFWebService?wsdl=============