网站首页 > 书籍教程 > ASP教程 > jre6的webservice使用Php类库nusoap调用的问题

jre6的webservice使用Php类库nusoap调用的问题

  • 作者:互联网
  • 时间:2010-02-02 16:03:45

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?wsdl
 

4

在创建nusoap对象时,都不能认为他是wsdl。也就是说这两个地址都是非wsdl的。
 

5

 

6


view sourceprint?1 2、命名空间问题
view sourceprint?1 大家都知道一般开发中,使用的命名空间都是“http://te***i.org/”,但是在这里不是,而变成了http://ws.csevent/
view sourceprint?1 可以使用
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查看

 

http://ws.csevent/" schemaLocation="http://192.168.53.43:8090/CSEventWS/TestWS?xsd=1"/>>

http://ws.csevent/"

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");