jre6.0入了对WebService的支持,不用再用开源类库了。
看看这样一段代码:
ver sourceprint?01 @WebService(name="TestWS",
02 serviceName="TestWS")
03 classe pública TestWS {
04 /**
05 * 测试相加方法
06 * @param x
07 * @param y
08 * @retorno
09 */
10 @WebMethod
11 public int TestMethod(int x,int y){
12 retorno x + y;
13}
14}
visualizar sourceprint?01 <PRE class=brush:java>/**
02 * @autor v.xieping
03 *
04 */
05 aula pública Programa {
06 /**
07 * @param argumentos
08 */
09 public static void main(String[] args) {
10 Ponto final.publish(
11" http://192.168.53.43:8090/CSEventWS/TestWS ",
12 novos TestWS());
13ThreadWaitor.keepWait();
14}
15}
16</PRÉ>
这样使用
visualizar impressão de origem?1 http://192.168.53.43:8090/CSEventWS/TestWS
view sourceprint?1 这个地址就可以访问到这个WebService。
visualizar impressão de origem?1
visualizar impressão de código-fonte?
view sourceprint?1 1、WSDL问题
visualizar impressão de origem?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>
visualizar impressão de origem?1 2、命名空间问题
visualizar impressão de código -fonte ?
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);
这种方式定义。
Acesse 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:esquema>
<xsd:importar namespace=" http://ws.csevent/ "
esquemaLocation=" http://192.168.53.43:8090/CSEventWS/TestWS?xsd=1"/ >
</xsd:esquema>
</types>
Acesse http://192.168.53.43:8090/CSEventWS/TestWS?xsd=1就可以看到用的参数名字。
<xs:complexType name="TestMethod">
−
<xs:sequência>
<xs:element name="arg0" type="xs:int"/>
<xs:element name="arg1" type="xs:int"/>
</xs:sequência>
</xs:complexType>
最终调用为:
注意:以下代码是使用的slightphp框架。实现了对nusoap的初级包装。
$objSoap = novo 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");