1.import java.net.MalformedURLException;
import java.net.URL;
import org.codehaus.xfire.client.Client;
//引用的xfire.client.Client包 publicclass ServiceTest {
publicstaticvoid main(String[] args) throws MalformedURLException, Exception {
// 根据 wsdl创建客户端
Client client =new Client(new URL()); // 客户端 反射 ws 方法与传递参数Object[] results = client .invoke("sayHello", new Object[] { "Firends" });
System.out.println(results[0]); }}
//这种方式的传递对于复杂对象是不成功的。可交互简单类型的数据。
2.
import java.net.MalformedURLException;
import org.codehaus.xfire.XFireFactory; import org.codehaus.xfire.client.XFireProxyFactory; import org.codehaus.xfire.service.Service; import org.codehaus.xfire.service.binding.ObjectServiceFactory; import com.yjm.ManagerService;// 注意看引入的包,有些包是xfire提供的包。
public class ServiceTest {
public static void main(String[] args) {
Service ser = new ObjectServiceFactory() .create(ManagerService.class);
XFireProxyFactory xFactory = new XFireProxyFactory(XFireFactory .newInstance().getXFire()); String url = ; try {// ms与服务器端交互复杂对象类型
ManagerService ms= (ManagerService) factory.create( ser , url); } catch (MalformedURLException e) { e.printStackTrace(); } }}
问题来了,不同java webservice框架之间是否可以传递复杂对象类型。本人目前在做一个xfire与axis之间传递复杂对象的问题。 如果传递的参数是复杂类型的需要 拷贝接口信息到客户端。如果返回类型是复杂类型的 需要再配置xml文件。如果返回的对象是复杂类型的 需要在 对象的包下配置 对象成员变量 复杂类型的映射,int string date 不用配置。如果返回的是集合 需要再接口下配置xml文件。xfire 默认的是没有配置文件 加载默认的 ,有配置文件加载配置文件里的。
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns:my="http://webservice.cks.itrus.com/zdca">
<mapping name="my:QueryCertResult">
<property name="certInfoList" componentType="com.itrus.webserviceVO.CertInfo" />
</mapping>
</mappings>
成员变量 certInfoList list集合里面的值是CertInfo对象需要配置一下。
接口方法配置,返回的是一个对象类型,该配置文件放在 接口包下
接口名.aegis.xml
实体bean 配置,实体bean 成员变量有一个list集合 该配置文件放在bean包下
类名.aegis.xml