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

 

posted @ 2010-02-01 18:13  Birdshover  阅读(1939)  评论(1编辑  收藏  举报