First they ignore you
then they ridicule you
then they fight you
then you win
    -- Mahatma Gandhi
Chinese => English     英文 => 中文             
随笔-221  评论-1047  文章-0  trackbacks-0
看了YanHua同学的《 用JRuby轻松搞定SOAP消息 》,也手痒了,那我就用Groovy来实现一个吧:)

0,下载jar包:http://dist.codehaus.org/groovy/jars/groovysoap-all-1.0-0.3-snapshot_jdk1.5.0.jar,
    并将其放置于<groovy_home>/lib目录中。


1,定义Hello类如下(保存为Hello.groovy,并放在classpath中,使Groovy能够找到该类):
class  Hello {  
    String hello(String name){  
        
return   " hello, "   +  name 
    }  
}

2,启动SoapServer:
import  groovy.net.soap.SoapServer

def server 
=   new  SoapServer( " localhost " 2007 )

server.setNode(
" Hello " )

server.start()

3,创建SoapClient,并调用相关服务:
import  groovy.net.soap.SoapClient

def proxy 
=   new  SoapClient( " http://localhost:2007/HelloInterface?wsdl " )

println proxy.hello(
" Daniel " )

结果如下所示:

hello,Daniel


附:朝花夕拾——Groovy & Grails

posted on 2007-06-15 19:58 山风小子 阅读(3022) 评论(6)  编辑  收藏 所属分类: Groovy & Grails