项目需要制作短信接口服务端,于是利用xfire和spring 结合,轻松构建webservice服务. 基本思路如下:
1. 加入所需要类包:
activation-1.1.jar
commons-codec-1.3
commons-httpclient-3.0
jaxen-1.1-beta-9
jdom-1.0
mail
stax-api-1.0.1
wsdl4j-1.6.1
xbean-spring-2.8
xfire-all-1.2.6
xfire-jsr181-api-1.0-M1
xml-apis-1.3.04
XmlSchema-1.4.2
2. 在web.xml中添加相关的配置文件:
<servlet>
<servlet-name>xfire</servlet-name>
<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>xfire</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>
3. 编写服务接口,实现类:
public interface SmsService {
public int insertMessage(String paramStr);
}
public class SmsServiceImpl implements SmsService{
public String insertMessage (String name) {
......
}
}
4. 服务接口的配置信息,在applicationContext-ws.xml文件中:
<bean id="SmsService" class="org.codehaus.xfire.spring.remoting.XFireExporter">
<property name="serviceFactory" ref="xfire.serviceFactory" />
<property name="xfire" ref="xfire" />
<property name="serviceBean" ref="smsBean" />
<property name="serviceClass" value="com.ailk.webservice.service.SmsService" />
<property name="name" value="SmsService" />
</bean>
至此,完成了服务端的构建;
5.编写客户端测试服务接口,具体实现略.