我正在尝试在Symfony中创建一个Web服务。我看过这些网,并尝试了所有这些网,但它们对我不起作用。
http://besim.pl/SoapBundle/soapserver/configuration.html
http://barandigoyen.wordpress.com/2012/07/13/como-implementar-un-web-service-wsdl-en-symfony-2/
有人可以一步一步地更好地解释这个过程吗?
非常感谢!!!
编辑:我遵循的步骤是:
1)将以下内容添加到composer.json
"require":{
...
"besimple/soap-bundle": "dev-master",
"besimple/soap-common": "dev-master",
"ass/xmlsecurity": "dev-master",
"besimple/soap-server": "dev-master",
"besimple/soap-client": "dev-master"
...
}
2)运行以下命令:
$ php composer.phar self-update
$ php composer.phar update
3)在app / AppKernel.php
中添加了以下内容public function registerBundles()
{
return array(
// ...
new BeSimple\SoapBundle\BeSimpleSoapBundle(),
// ...
);
}
4)在app / config / config.yml
中添加了以下内容be_simple_soap:
cache:
type: disk
lifetime: 86400
limit: 5
services:
AplicationService:
namespace: http://localhost/myproject/web/app_dev.php/ws/AplicationService
binding: rpc-literal
resource: “@StaticBundle/Controller/WebServiceController.php“
resource_type: annotation
5)在app / config / routing.yml
中添加了以下内容_besimple_soap:
resource: "@BeSimpleSoapBundle/Resources/config/routing/webservicecontroller.xml"
prefix: /ws
6)在StaticBundle中创建以下Controller
namespace myproject\StaticBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class WebServiceController extends Controller
{
/**
* @Soap\Method("hello")
* @Soap\Param("name", phpType = "string")
* @Soap\Result(phpType = "string")
*/
public function helloAction($name)
{
return sprintf('Hello %s!', $name);
}
/**
* @Soap\Method("goodbye")
* @Soap\Param("name", phpType = "string")
* @Soap\Result(phpType = "string")
*/
public function goodbyeAction($name)
{
return $this->container->get('besimple.soap.response')->setReturnValue(sprintf('Goodbye %s!', $name));
}
}
7)访问localhost/myproject/web/app_dev.php/ws/AplicationService?wsdl
并获取错误代码为500的xml。
答案 0 :(得分:1)
好吧,检查日志我发现了这个问题的原因: 更正config.yml的双引号:
resource: "@StaticBundle/Controller/WebServiceController.php"
their example有奇怪的双引号;)
答案 1 :(得分:0)
在步骤6中,您似乎缺少注释中Soap的use
语句。
http://besim.pl/SoapBundle/soapserver/configuration.html#annotations-for-controllers
尝试:
namespace myproject\StaticBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
class WebServiceController extends Controller
{
/**
* @Soap\Method("hello")
* @Soap\Param("name", phpType = "string")
* @Soap\Result(phpType = "string")
*/
public function helloAction($name)
{
return sprintf('Hello %s!', $name);
}
/**
* @Soap\Method("goodbye")
* @Soap\Param("name", phpType = "string")
* @Soap\Result(phpType = "string")
*/
public function goodbyeAction($name)
{
return $this->container->get('besimple.soap.response')->setReturnValue(sprintf('Goodbye %s!', $name));
}
}