jre6.0加入了对WebService的支持,不用再用开源类库了。
看看这样一段代码:
view sourceprint?01 @WebService(name="TestWS",
02 serviceName="TestWS")
03 public class TestWS {
04 /**
05 * 测试相加方法
06 * @param x
07 * @param y
08 * @return
09 */
10 @WebMethod
11 public int TestMethod(int x,int y){
12 return x + y;
13 }
14 }
view sourceprint?01
/**02 * @author v.***ping
03 *
04 */
05 public class Program {
06 /**
07 * @param args
08 */
09 public static void main(String[] args) {
10 En***int.publish(
11 "http://192.168.53.43:8090/CSEventWS/TestWS",
12 new TestWS());
13 Th***dWaitor.keepWait();
14 }
15 }
16
这样使用
view sourceprint?1 http://192.168.53.43:8090/CSEventWS/TestWS
view sourceprint?1 这个地址就可以访问到这个WebService。
view sourceprint?1
view sourceprint?1 但是有个奇怪的问题是,我是一nusoap类库不能像以前一样调用成功。经试验发现三个问题。
view sourceprint?1 1、WSDL问题
view sourceprint?1 不过使用地址
http://192.168.53.43:8090/CSEventWS/TestWS
2
还是地址
3
http://192.168.53.43:8090/CSEventWS/TestWS?wsdl4
在创建nusoap对象时,都不能认为他是wsdl。也就是说这两个地址都是非wsdl的。5
6
http://192.168.53.43:8090/CSEventWS/TestWS?wsdl
2
这样的地址查看http://ws.csevent/" name="TestWS">
3
3、参数问题
一般WSDL地址的参数是和名字相关的。但是这里不是,而要用
$params = array('arg0' => 100,'arg1' => 200);
这种方式定义。
可以通过http://192.168.53.43:8090/CSEventWS/TestWS?wsdl查看
−
schemaLocation="http://192.168.53.43:8090/CSEventWS/TestWS?xsd=1"/>
再继续打开http://192.168.53.43:8090/CSEventWS/TestWS?xsd=1 就可以看到用的参数名字。
−
最终调用为:
注意:以下代码是使用的slightphp框架。实现了对nusoap的初级包装。
$objSoap = new HTTP_SOAP();
$client = $objSoap->getClient($this->url,false);
$params = array('arg0' => 100,'arg1' => 200);
$r = $client->call('TestMethod',$params ,'http://ws.csevent/','',false,true);
Debug_Util::log($r,"se***ce.log");
上一篇: 控制参数个数的几种方式
下一篇: memcached的最新状态