Groovy高效编程——用Groovy轻松搞定SOAP消息

Groovy高效编程——用Groovy轻松搞定SOAP消息

看了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

原文:http://www.blogjava.net/BlueSUN/archive/2007/06/15/124567.html

你可能感兴趣的:(jdk,编程,SOAP,import,groovy,jruby)