首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

webservice spring xfire的范例

2012-11-06 
webservice spring xfire的实例package servicepublic interface HelloWorld {String sayHelloWorld(Stri

webservice spring xfire的实例

package service;
public interface HelloWorld {

String sayHelloWorld(String name);
}

?

package service.impl;

import service.HelloWorld;

public class HelloWorldImpl implements HelloWorld {
?public String sayHelloWorld(String name) {
??String helloWorld = "hello," + name;
??return helloWorld;
?}
}

?

src目录下:

applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans
?xmlns="http://www.springframework.org/schema/beans"
?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
?xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

?<bean id="HelloWorldBean" encoding="UTF-8"?>
<beans
?xmlns="http://www.springframework.org/schema/beans"
?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
?xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

?<bean id="HelloWorldBean" encoding="UTF-8"?>
<beans
?xmlns="http://www.springframework.org/schema/beans"
?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
?xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

?<!-- 引入XFire预配置信息 -->
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
<!--? 定义访问的url-->
<bean />
</entry>
</map>
</property>
</bean>
<!-- 使用XFire导出器 -->
<bean id="baseWebService" lazy-init="false" abstract="true">
<!-- 引用xfire.xml中定义的工厂 -->
<property name="serviceFactory" ref="xfire.serviceFactory" />
<!-- 引用xfire.xml中的xfire实例 -->
<property name="xfire" ref="xfire" />
</bean>
<bean id="HelloWorldService" parent="baseWebService">
<!-- 业务服务bean -->
<property name="serviceBean" ref="HelloWorldBean" />
<!-- 业务服务bean的窄接口类 -->
<property name="serviceClass" value="service.HelloWorld" />
</bean>

?

public class WebServiceClientTest {
??HelloWorld helloWorld = null;
??public static void main(String[] args) {//运行这个类,tomcat 必须是启动的
???WebServiceClientTest test = new WebServiceClientTest();
???test.testClient();
??}
??
??public void testClient() { //spring2调用服务
???ApplicationContext ctx = new ClassPathXmlApplicationContext("client.xml");
???helloWorld = (HelloWorld) ctx.getBean("testWebService");
???System.out.println(helloWorld.sayHelloWorld("阿蜜果"));
??}
}

?

public class WebServiceClientTest {?????? //运行这个类,必须启动tomcat
??HelloWorld helloWorld = null;
??public static void main(String[] args) throws Exception {
???WebServiceClientTest test = new WebServiceClientTest();
???test.testClient();
???}
??
??//通过WSDL文件生成客户端调用程序
??public void testClient() throws Exception {
???String wsdl = "HelloWorldService.wsdl"; //对应的WSDL文件
?????????? Resource resource = new ClassPathResource(wsdl);
???Client client = new Client(resource.getInputStream(), null); //根据WSDL创建客户实例
???
???Object[] objArray = new Object[1];
???objArray[0] = "阿蜜果";
???//调用特定的Web Service方法
?????????? Object[] results = client.invoke("sayHelloWorld", objArray);
???System.out.println("result: " + results[0]);
??}
}

----------------------------------------

?

//返回对象:

creationComplete="WS.getDataList.send()"

?

<mx:operation name="getDataList" resultFormat="object">

?

<mx:DataGrid x="4.5" y="0" dataProvider="{WS.getDataList.lastResult}">
???<mx:columns>
????<mx:DataGridColumn headerText="用户编号" dataField="id"/>
????<mx:DataGridColumn headerText="姓" dataField="lastName"/>
????<mx:DataGridColumn headerText="名" dataField="firstName"/>
???</mx:columns>
??</mx:DataGrid>

?

public interface HelloWorld {

String sayHelloWorld(String name);
public List<User> getDataList();
}

?

public class User {
?private int id;
?private String firstName;//和dataGrid对应
?private String lastName;

}

?

热点排行