Estou estudando sobre webservices e me deparei com uma dúvida.
E o seguinte, gerei um wsdl atravez do Axis versão 1.6 . A classe e somente para testes, ela só soma dois números passados como parametro e retorna o resultado.
Gostaria de saber se tem como eu consumir este serviço de forma externa, atravez de JavaScript/Ajax.
Somar.jws
<?xml version="1.0" encoding="UTF-8"?>
-<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:intf="http://localhost:8480/axis/Somar.jws" xmlns:impl="http://localhost:8480/axis/Somar.jws" xmlns:apachesoap="http://xml.apache.org/xml-soap" targetNamespace="http://localhost:8480/axis/Somar.jws">
<!--WSDL created by Apache Axis version: 1.4 Built on Apr 22, 2006 (06:55:48 PDT)-->
-<wsdl:message name="somaResponse"> <wsdl:part name="somaReturn" type="xsd:int"/> </wsdl:message> -<wsdl:message name="somaRequest"> <wsdl:part name="valor1" type="xsd:string"/> <wsdl:part name="valor2" type="xsd:string"/> </wsdl:message> -<wsdl:portType name="Somar"> -<wsdl:operation name="soma" parameterOrder="valor1 valor2"> <wsdl:input name="somaRequest" message="impl:somaRequest"/> <wsdl:output name="somaResponse" message="impl:somaResponse"/> </wsdl:operation> </wsdl:portType> -<wsdl:binding name="SomarSoapBinding" type="impl:Somar"> <wsdlsoap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/> -<wsdl:operation name="soma"> <wsdlsoap:operation soapAction=""/> -<wsdl:input name="somaRequest"> <wsdlsoap:body use="encoded" namespace="http://DefaultNamespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </wsdl:input> -<wsdl:output name="somaResponse"> <wsdlsoap:body use="encoded" namespace="http://localhost:8480/axis/Somar.jws" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </wsdl:output> </wsdl:operation> </wsdl:binding> -<wsdl:service name="SomarService"> -<wsdl:port name="Somar" binding="impl:SomarSoapBinding"> <wsdlsoap:address location="http://localhost:8480/axis/Somar.jws"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
Teste.html
<html>
<head ><!-- runat="server"-->
<title>Teste de Webservice</title>
<script language="javascript" type="text/javascript" src="chamar_service.js"></script>
</head>
<body>
<form id="testes" method="post">
<p>
Preencha os dados e clique em calcular</p>
<div>
Primeiro Valor:<br />
<input type="text" id="value1" name="value1"/>
<br />
<br />
Segundo Valor:<br />
<input type="text" id="value2" name="value2"/>
<br />
<br />
<button type="submit" onclick="CallWs();">
Calcular</button>
</div>
</form>
<hr />
<p>
Resposta do servidor</p>
<div id="divResponse">
</div>
</body>
</html>
Somar.java
public class Somar {
public int soma(String valor1, String valor2){
return Integer.parseInt (valor1) + Integer.parseInt (valor2);
}
}