xFire两种客户端的传递参数

 

1.None.gif
import
 java.net.MalformedURLException;java

import java.net.URL;web

import org.codehaus.xfire.client.Client;服务器

  //引用的xfire.client.Client包
   publicclass ServiceTest {
app

 publicstaticvoid main(String[] args) throws MalformedURLException, Exception {框架

        // 根据 wsdl建立客户端
        Client client =new Client(new URL(http://localhost:8080/项目名/services/service名?wsdl));
        //  客户端 反射 ws 方法与传递参数
ide

        Object[] results = client .invoke("sayHello"new Object[] "Firends" });
url

        System.out.println(results[0]);
    }

}

spa

//这种方式的传递对于复杂对象是不成功的。可交互简单类型的数据。.net

 

 

2.code

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 = http://localhost:8080/项目名/services/service名;
        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

<?xml version="1.0" encoding="UTF-8"?>
<mappings>
	<mapping xmlns="http://webservice.cks.itrus.com/zdca">
		<method name="queryCerts">
			<parameter index="0" componentType="com.itrus.webserviceVO.UserInfo" />
			<return-type componentType="com.itrus.webserviceVO.QueryCertResult" />
		</method>
	</mapping>
</mappings>


实体bean 配置,实体bean 成员变量有一个list集合  该配置文件放在bean包下


类名.aegis.xml

<?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>