百度空间 | 百度首页 
 
查看文章
 
spring+xfire+webservice+helloworld
2007-07-24 10:25

spring+xfire+webservice+helloworld


Echo.java
package org.codehaus.xfire.spring.example;
public interface Echo{
    String echo(String in);
}
EchoImpl.java
package org.codehaus.xfire.spring.example;
public class EchoImpl   implements Echo{
    public String echo(String in){
        return in;
     }
}
applicationContext.xml
<?xml version=1.0 encoding=UTF-8?>
<beans>
     <bean id=echoBean class=org.codehaus.xfire.spring.example.EchoImpl/>
</beans>
这上面的就最简单的spring IoC 下helloworld的例子
这文件xfire-servlet.xml配置是关键:
xfire-servlet.xml
<?xml version=1.0 encoding=UTF-8?>
<beans>
     <bean class=org.springframework.web.servlet.handler.SimpleUrlHandlerMapping>
         <property name=urlMap>
             <map>
                 <entry key=/EchoService>
                     <ref bean=echo>
                 </entry>
             </map>
         </property>
     </bean>
     <bean id=echo     class=org.codehaus.xfire.spring.remoting.XFireExporter>
         <property name=serviceFactory>
             <ref bean=xfire.serviceFactory
         </property>
         <property name=xfire>
             <ref bean=xfire
         </property>
         <property name=serviceBean>
             <ref bean=echoBean
         </property>
         <property name=serviceClass>
             <value>org.codehaus.xfire.spring.example.Echo</value>
         </property>
     </bean>
</beans>
接下来是客户端的test就更简单了
客户端

applicationContext-client.xml
<?xml version=1.0 encoding=UTF-8?>
<beans>
<beanid=testWebService class=org.codehaus.xfire.spring.remoting.XFireClientFactoryBean>
       <property name=serviceClass>
          <value>org.codehaus.xfire.spring.example.Echo</value>
       </property>
       <property name=wsdlDocumentUrl>
         <value>http://127.0.0.1:8080/xfire/EchoService?wsdl</value>
       </property>
      </bean>
<beans>
package test;
import java.util.*;
import junit.framework.TestCase;
import org.codehaus.xfire.spring.example.*;
public class WebServiceClientTest extends TestCase {
Echo echo=null;
static {
ApplicationContextFactory.init(/test/applicationContext-client.xml);
}
public static void main(String[] args) {
junit.swingui.TestRunner.run(PlayContextDaoTest.class);
}
protected void setUp() throws Exception {
echo=(Echo)ApplicationContextFactory.getApplicationContext().getBean(testWebService);
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public  void testCilient(){
    System.out.print(echo.echo(haoha i haohao));
}
}

类别:默认分类 | | 添加到搜藏 | 分享到i贴吧 | 浏览() | 评论 (1)
 
最近读者:
 
网友评论:
1
2008-08-21 15:31 | 回复
study.
 
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2010 Baidu