·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP网站建设 >> jre6的webservice使用Php类库nusoap调用的问题

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

作者:佚名      ASP网站建设编辑:admin      更新时间:2022-07-23
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 <PRE class=brush:java>/**  

02  * @author v.xieping  

03  *  

04  */

05 public class Program {  

06     /**  

07      * @param args  

08      */

09     public static void main(String[] args) {  

10         Endpoint.publish(  

11                  "http://192.168.53.43:8090/CSEventWS/TestWS",  

12                  new TestWS());  

13         ThreadWaitor.keepWait();  

14     }  

15 }  

16 </PRE>



这样使用

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 不过使用地址<PRE class=brush:java>http://192.168.53.43:8090/CSEventWS/TestWS</PRE>  

2 <PRE class=brush:java>还是地址</PRE>  

3 <PRE class=brush:java><PRE class=brush:java>http://192.168.53.43:8090/CSEventWS/TestWS?wsdl</PRE>  

4 <PRE class=brush:java>在创建nusoap对象时,都不能认为他是wsdl。也就是说这两个地址都是非wsdl的。</PRE>  

5 <PRE class=brush:java></PRE>  

6 </PRE>
view sourceprint?1 2、命名空间问题
view sourceprint?1 大家都知道一般开发中,使用的命名空间都是“http://tempuri.org/”,但是在这里不是,而变成了http://ws.csevent/。
view sourceprint?1 可以使用 <PRE class=brush:java>http://192.168.53.43:8090/CSEventWS/TestWS?wsdl</PRE>  

2 <PRE class=brush:java>这样的地址查看 <definitions targetNamespace="http://ws.csevent/" name="TestWS"></PRE>  

3 <PRE class=brush:java></PRE>

3、参数问题

一般WSDL地址的参数是和名字相关的。但是这里不是,而要用

$params = array('arg0' => 100,'arg1' => 200);

这种方式定义。



可以通过http://192.168.53.43:8090/CSEventWS/TestWS?wsdl查看



<types>&#8722;<xsd:schema><xsd:import namespace="http://ws.csevent/" schemaLocation="http://192.168.53.43:8090/CSEventWS/TestWS?xsd=1"/></xsd:schema></types><types>

&#8722;<xsd:schema>

<xsd:import namespace="http://ws.csevent/"

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

</xsd:schema>

</types>

再继续打开http://192.168.53.43:8090/CSEventWS/TestWS?xsd=1 就可以看到用的参数名字。




<xs:complexType name="TestMethod">

&#8722;

<xs:sequence>

<xs:element name="arg0" type="xs:int"/>

<xs:element name="arg1" type="xs:int"/>

</xs:sequence>

</xs:complexType>



最终调用为:

注意:以下代码是使用的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,"service.log");