Salve a tutti,
ho realizzato un semplicissimo Web Service SOAP in java e vorrei interfacciarmi ad esso con un client SOAP PHP, ma ho dei problemi poichè le chiamate PHP non fanno match con la firma dei metodi java a causa di tipi.
Codice Java Server
Codice PHP:
package it.test.webservice;
import javax.faces.bean.ManagedProperty;
import javax.jws.WebMethod;
import javax.jws.WebService;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
@WebService
public class OperaService {
@WebMethod
public String getOperaName(int codiceCatastale){
Session session = ConnectionDb.getInstance().openSession();
Opera opera = (Opera) session.createCriteria(Opera.class).add(Restrictions.eq("codiceCatastale", codiceCatastale)).uniqueResult();
int cod = opera.getCodiceCatastale();
session.close();
return "Nome : " + cod;
}
@WebMethod
public String getQualcosa(){
return "qualcosa";
}
}
il file WSDL non lo posto poichè non credo che in questo caso serva a risolvere il problema.
Mentre il codice PHP è il seguente
Codice PHP:
<?php
$wsdl_url="http://localhost:8080/wsdl/OperaService.wsdl";
$client = new SoapClient($wsdl_url);
echo $client->getQualcosa();
echo $client->getOperaName(324234);
?>
Mentre se mi ci interfaccio in java tutto funziona correttamente
Esempio di client Java, una semplicissima servlet
Codice PHP:
/**
* Servlet implementation class Test
*/
@WebServlet("/Test")
public class Test extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Test() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
OperaService operaService;
try {
operaService = new OperaServiceServiceLocator().getOperaService();
response.getWriter().write(operaService.getOperaName(7594681) + "
");
response.getWriter().write(operaService.getQualcosa());
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
Gli errori che mi vengono forniti sono i seguenti:
codice:
Catchable fatal error: Object of class stdClass could not be converted to string in C:\xampp\htdocs\TestWSPhp\testWs.php on line 5
codice:
Tried to invoke method public java.lang.String it.test.webservice.OperaService.getOperaName(int) with arguments null. The arguments do not match the signature.; nested exception is: java.lang.IllegalArgumentException in C:\xampp\htdocs\TestWSPhp\testWs.php:5