I'm working with BeSimpleSOAPBundle to do my web service on symfony2 . I test my web service with SOA Client extension firefox and I can see that my web service it's ok , but when Try to test with javascript this fails. I get the following mistakes from console browser
OPTIONS http://192.168.0.68/controlid/web/app_dev.php/ws/loginOperador?wdls 405 (Method Not Allowed) jquery.js:4
OPTIONS http://192.168.0.68/controlid/web/app_dev.php/ws/loginOperador?wdls No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. jquery.js:4
XMLHttpRequest cannot load http://192.168.0.68/controlid/web/app_dev.php/ws/loginOperador?wdls. No 'Access-Control- Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. (index):1
The next code is the way to call my web service with javascript
function CallService()
{
var webServiceURL = 'http://192.168.0.68/controlid/web/app_dev.php/ws/loginOperador?wdls';
var soapMessage = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><goodbye xmlns="http://controlid/ws/loginOperador/1.0/"><name>'+$('#nombre').val()+'</name></goodbye></soap:Body></soap:Envelope>';
jQuery.support.cors = true;
//Llamamos a la función AJAX de JQuery
$.ajax({
type: "POST",
url: webServiceURL,
crossDomain : true,
cache: false,
data: soapMessage,
processData: false,
dataType: "xml",
contentType: "application/soap+xml; charset=utf-8",
success: OnSuccess,
error: OnError
});
return false;
}
This is the code of my web services on symfony:
/**
* Método que se encarga de verificar si un operador
* puede tener acceso desde la aplicación móvil.
*
* @Soap\Method("login")
* @Soap\Param("pin", phpType = "string")
* @Soap\Result(phpType = "string")
*/
public function loginAction( $pin )
{
$em = $this->container->get('doctrine')->getEntityManager();
try
{
$operador = $em->getRepository('controlidRondasBundle:Operador')->findOneBy(array('pin'=>$pin));
if( empty($operador) )
{
return sprintf('Acceso denegado');
}
else{
return sprintf('Bienvenido %s!', $operador->getNombre() );
}
}
catch (\Doctrine\Orm\NoResultException $e)
{
return sprintf('Acceso denegado');
}
}
An this is the setup of my service on symfony ( app/conf/config.yml)
be_simple_soap:
services:
DemoApi:
namespace: http://controlid/ws/DemoApi/1.0/
binding: rpc-literal
resource: "@controlidRondasBundle/Controller/RegisterController.php"
resource_type: annotation
loginOperador:
namespace: http://controlid/ws/loginOperador/1.0/
binding: rpc-literal
resource: "@controlidSeguridadBundle/Controller/OperatorSecurityController.php"
resource_type: annotation
And routing_dev.yml:
_besimple_soap:
resource: "@BeSimpleSoapBundle/Resources/config/routing/webservicecontroller.xml"
prefix: /ws
Someone could say me what do I'm doing wrong please?