一、SEI的定义
假设有以下SEI定义:
Java代码
- @WebService
- public interface OrderProcess {
- public String processOrder(Order order);
- }
@WebService public interface OrderProcess { public String processOrder(Order order); }
(实现端省略)
二、Server端发布
则最简单的发布Server的方式可以如下:
Java代码
- Endpoint.publish("http://localhost:8181/orderProcess", new OrderProcessImpl());
Endpoint.publish("http://localhost:8181/orderProcess", new OrderProcessImpl());
或者是spring的方式:
Xml代码
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:jaxws="http://cxf.apache.org/jaxws"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="
- http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
- <import resource="classpath:META-INF/cxf/cxf.xml" />
- <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
- <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
- <jaxws:endpoint id="orderProcess"
- implementor="com.liulutu.liugang.cxf.jaxws.OrderProcessImpl" address="http://localhost:8090/orderProcess" />
- </beans>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <jaxws:endpoint id="orderProcess" implementor="com.liulutu.liugang.cxf.jaxws.OrderProcessImpl" address="http://localhost:8090/orderProcess" /> </beans>
三、Client端调用
Java代码
- Service service = Service.create(new URL("<wsdlfilepath>"),
- new QName("namespace", "servicename"));
- OrderProcess port = orderProcessService.getPort(OrderProcess.class);
- String s = port.processOrder(<arg>);
- System.out.println(s);
Service service = Service.create(new URL("<wsdlfilepath>"), new QName("namespace", "servicename")); OrderProcess port = orderProcessService.getPort(OrderProcess.class); String s = port.processOrder(<arg>); System.out.println(s);
或者Spring的方式:
Xml代码
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:jaxws="http://cxf.apache.org/jaxws"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://cxf.apache.org/jaxws
- http://cxf.apache.org/schemas/jaxws.xsd">
- <jaxws:client id="orderClient"
- serviceClass="com.liulutu.liugang.cxf.codefirst.OrderProcess"
- address="http://localhost:8181/orderProcess" />
- </beans>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <jaxws:client id="orderClient" serviceClass="com.liulutu.liugang.cxf.codefirst.OrderProcess" address="http://localhost:8181/orderProcess" /> </beans>
然后在Java代码里:
Java代码
- ClassPathXmlApplicationContext xmlApplicationContext = new ClassPathXmlApplicationContext(
- "/META-INF/spring/jaxwsspringclient.xml");
- OrderProcess bean = xmlApplicationContext.getBean(OrderProcess.class);
- System.out.println(bean.processOrder(<order>));
时间: 2024-11-12 10:24:37