日期:2014-05-16 浏览次数:20388 次
package com.tuscanytest.service; import java.util.List; import org.osoa.sca.annotations.Remotable; @Remotable public interface IUserservice { //如果服务是分布式的,就需要使用@Remotable声明 List<User> getAll(); }
package com.tuscanytest.service; public class User { private String id; private String name; private String password; private Address address; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } }
package com.tuscanytest.service; public class Address { private String street; public String getStreet() { return street; } public void setStreet(String street) { this.street = street; } }
package com.tuscanytest.service; import java.util.ArrayList; import java.util.List; public class UserServiceImpl implements IUserservice { private static List<User> users = null; static { users = new ArrayList<User>(); for (int i = 0; i < 10; i++) { User user = new User(); user.setId("id" + i); user.setName("name" + i); user.setPassword("password" + i); Address address = new Address(); address.setStreet("street" + i); user.setAddress(address); users.add(user); } } public List<User> getAll() { return users; } }
<?xml version="1.0" encoding="UTF-8"?> <composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" name="tuscanytest" targetNamespace="http://serivce.tuscanytest.com"> <component name="UserServiceImpl"> <implementation.java class="com.tuscanytest.service.UserServiceImpl"></implementation.java> </component> <service name="UserService" promote="UserServiceImpl"> <interface.java interface="com.tuscanytest.service.IUserservice" /> <binding.ws></binding.ws> <!--定义了发布服务绑定的协议,使用webservice,还有其他多种协议绑定,可参考tuscany文档--> <tuscany:binding.jsonrpc></tuscany:binding.jsonrpc> <!--和web服务相比增加上面一行配置,就实现了jsonrpc支持--> </service> </composite>
<?xml version="1.0" encoding="UTF-8"?> <contribution xmlns="http://www.osoa.org/xmlns/sca/1.0" targetNamespace="http://serivce.tuscanytest.com" xmlns:tus