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

  • 相关阅读:
    读书笔记——吴军《态度》
    JZYZOJ1237 教授的测试 dfs
    NOI1999 JZYZOJ1289 棋盘分割 dp 方差的数学结论
    [JZYZOJ 1288][洛谷 1005] NOIP2007 矩阵取数 dp 高精度
    POJ 3904 JZYZOJ 1202 Sky Code 莫比乌斯反演 组合数
    POJ2157 Check the difficulty of problems 概率DP
    HDU3853 LOOPS 期望DP 简单
    Codeforces 148D. Bag of mice 概率dp
    POJ3071 Football 概率DP 简单
    HDU4405 Aeroplane chess 飞行棋 期望dp 简单
  • 原文地址:https://www.cnblogs.com/birdshover/p/1661239.html
Copyright © 2011-2022 走看看