zoukankan      html  css  js  c++  java
  • jre6的webservice使用Php类库nusoap调用的问题

    jre6.0加入了对WebService的支持,不用再用开源类库了。

    看看这样一段代码:

    @WebService(name="TestWS",
    		serviceName="TestWS")
    public class TestWS {
    	/**
    	 * 测试相加方法
    	 * @param x
    	 * @param y
    	 * @return
    	 */
    	@WebMethod
    	public int TestMethod(int x,int y){
    		return x + y;
    	}
    }
    
    
    /**
     * @author v.xieping
     *
     */
    public class Program {
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		Endpoint.publish(
    		         "http://192.168.53.43:8090/CSEventWS/TestWS",
    		         new TestWS());
    		ThreadWaitor.keepWait();
    	}
    }
    

    这样使用

    http://192.168.53.43:8090/CSEventWS/TestWS
    这个地址就可以访问到这个WebService。
    
    
    但是有个奇怪的问题是,我是一nusoap类库不能像以前一样调用成功。经试验发现三个问题。
    1、WSDL问题
    不过使用地址
    http://192.168.53.43:8090/CSEventWS/TestWS
    还是地址
    http://192.168.53.43:8090/CSEventWS/TestWS?wsdl
    在创建nusoap对象时,都不能认为他是wsdl。也就是说这两个地址都是非wsdl的。
    
    
    2、命名空间问题
    大家都知道一般开发中,使用的命名空间都是“http://tempuri.org/”,但是在这里不是,而变成了http://ws.csevent/。
    可以使用 
    http://192.168.53.43:8090/CSEventWS/TestWS?wsdl
    这样的地址查看 <definitions targetNamespace="http://ws.csevent/" name="TestWS">
    
    

    3、参数问题

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

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

    这种方式定义。

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

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

    <types>

    −<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">

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

  • 相关阅读:
    数组初始化
    排序算法
    fast rcnn,faster rcnn使用cudann加速问题
    「不啰嗦」和「说清楚」-20141223早读课
    加州理工学院公开课:机器学习与数据挖掘_Regularization(第十二课)
    2014年百度之星程序设计大赛
    一个伟大的发现,装X一下。笔记本win7系统64位机器执行unity 时,屏幕模糊解决的方法
    面向对象基础——类与对象的定义
    hdu1325 Is It A Tree?(二叉树的推断)
    持续集成(CI)工具------Hudson/Jenkins(Continuous Integration)安装与配置具体解释
  • 原文地址:https://www.cnblogs.com/birdshover/p/1661239.html
Copyright © 2011-2022 走看看