用xfire开发webservice

最近这一周一直在做webservice。用xfire和spring结合做的。开始遇见很多问题。这里得谢谢阿敏司令给的一些提示。在这里给出一个demo主要是客户端传pojo里面在封装list这样的大对像。部署spring和xfire的环境是很简单的 修改web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/xfire-servlet.xml
</param-value>
</context-param>
<servlet>
<servlet-name>xfire</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>xfire</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
增加xfire-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/>
<import resource="applicationContext.xml"/>
<bean
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<!-- 配置 service 名称和 Service Bean -->
<!-- -->
<entry key="/UserService.ws">
<ref bean="userService" />
</entry>

</map>
</property>
</bean>
<bean id="baseWebService" class="org.codehaus.xfire.spring.remoting.XFireExporter" lazy-init="false" abstract="true">
<property name="serviceFactory" >
<ref bean="xfire.serviceFactory"/>
</property>

<property name="xfire" >
<ref bean="xfire"/>
</property>
</bean>
<!-- 测试用的-->
<bean id="userService" parent="baseWebService">
<property name="serviceBean" >
<ref bean="userbean"/>
</property>
<property name="serviceClass" >
<value>test.service.Userservice</value>
</property>
</bean>

</beans>
配置applicationcontext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans >

<!-- -->
<bean id="userbean" class="test.service.imp.UserserviceImp"></bean>

</beans>
配置client.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- anthor zhangkt -->
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans >
<!-- 获取用户信息的例子 测试 -->
<bean id="testUserWebService" class="org.codehaus.xfire.spring.remoting.XFireClientFactoryBean" lazy-init="true">
<property name="serviceClass">
<value>test.service.Userservice</value>
</property>
<property name="wsdlDocumentUrl">
<value>http://127.0.0.1:8080/Test/services/UserService.ws?wsdl</value>
</property>
</bean>
</beans>
java文件
package test;

import java.util.List;

public class UserList implements java.io.Serializable{
private User user;

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}
private List <User> u;

public List<User> getU() {
return u;
}

public void setU(List<User> u) {
this.u = u;
}
}
package test;

public class User {
private String age;
private String longName;

public String getAge() {
return age;
}

public void setAge(String age) {
this.age = age;
}

public String getLongName() {
return longName;
}

public void setLongName(String longName) {
this.longName = longName;
}
}

package test.service;


import java.util.List;
import test.UserList;
import test.User;

public interface Userservice {
public String createUser(UserList userList);
public String getLi();
public void ListUser(UserList u);
}
package test.service.imp;

import test.service.Userservice;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import test.User;
import test.UserList;

public class UserserviceImp implements Userservice{



public String createUser(UserList userList) {
User user=userList.getUser();
System.out.println(user.getLongName());
return "1";
}

public String getLi( ) {
// TODO Auto-generated method stub
return "12";
}

public void ListUser(UserList u) {
// TODO Auto-generated method stub
List <User> li=u.getU();
for(User user:li){
System.out.println(user.getLongName());
}
}



}
主要注意序列化和jdk1.5的特性。1.4的还没去研究
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值