我有第一个用symfony3制作的Soap服务器示例。
这是我的WSDL:
<definitions name="StackOverFlowerService"
targetNamespace="http://localhost/stackoverflower/soap/stackoverflower.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://localhost/stackoverflower/soap/stackoverflower.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="NewRequest">
<part name="name" type="xsd:string"/>
</message>
<message name="NewResponse">
<part name="status" type="xsd:string"/>
</message>
<message name="getListRequest"></message>
<message name="getListResponse">
<part name="list" type="xsd:string"/>
</message>
<portType name="StackOverFlower_PortType">
<operation name="newStack">
<input message="tns:NewRequest"/>
<output message="tns:NewResponse"/>
</operation>
<operation name="getList">
<input message="tns:getListRequest"/>
<output message="tns:getListResponse"/>
</operation>
</portType>
<binding name="StackOverFlower_Binding" type="tns:StackOverFlower_PortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="newStack">
<soap:operation soapAction="newStack"/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:uniski:new"
use="encoded"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:uniski:new"
use="encoded"/>
</output>
</operation>
<operation name="getList">
<soap:operation soapAction="getList"/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:uniski:get-list"
use="encoded"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:uniski:get-list"
use="encoded"/>
</output>
</operation>
</binding>
<service name="StackOverFlower_Service">
<documentation>Description File of StackOverFlowerService</documentation>
<port binding="tns:StackOverFlower_Binding" name="StackOverFlower_Port">
<soap:address
location="http://localhost/stackoverflower/soap/" />
</port>
</service>
我也有服务:
<?php
namespace MyBundle\Service;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
class StackOverFlowerService {
private $em;
private $stackoverflower;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
public function newStack($name)
{
/*
$stackoverflower = new StackOverFlower();
$stackoverflower->setName($name);
$this->em->persist($stackoverflower);
$this->em->flush();
*/
return "ok";
}
public function getList()
{
$stackoverflowers = array(
array('id' => '001', 'name' => 'stack 001'),
array('id' => '002', 'name' => 'stack 002'),
array('id' => '003', 'name' => 'stack 003')
);
return $stackoverflowers;
}
} }
我的服务。yml
services:
stackoverflower_service:
class: MyBundle\Service\StackOverFlowerService
arguments: ["@doctrine.orm.entity_manager"]
最后,我有了像这样的独特的SOAP服务器和SOAP客户端控制器:
<?php
namespace MyBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class StackOverFlowerController extends Controller
{
/**
* @Route("/stackoverflower/soap", name="test_soap")
* @Method("GET")
*/
public function indexAction()
{
ini_set("soap.wsdl_cache_enabled", "0");
$options = array(
'uri' => 'http://uniski.com.devel/stackoverflower/soap',
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => true
);
$server = new \SoapServer(dirname(__FILE__).'/../../../web/soap/stackoverflower.wsdl', $options);
$server->setObject($this->get('stackoverflower_service'));
$response = new Response();
$response->headers->set('Content-Type', 'text/xml; charset=utf-8');
ob_start();
$server->handle();
$response->setContent(ob_get_clean());
return $response;
}
/**
* @Route("/stackoverflower/test-new", name="test_new")
* @Method("GET")
*/
public function testNewAction(Request $request)
{
$service = $this->get('stackoverflower_service');
$result = $service->newStack($request->query->get('name'));
return $this->render('PrestigeBundle:Soap:default.html.twig', array('status' => $result));
}
/**
* @Route("/stackoverflower/test-list", name="test_list")
* @Method("GET")
*/
public function testGetListAction(Request $request)
{
try {
/*
$service = $this->get('stackoverflower_service');
$result = $service->getList();
return $this->render('PrestigeBundle:Soap:default.html.twig', array('list' => $result));
*/
$client = new \SoapClient("http://uniski.com.devel/stackoverflower/soap?wsdl", array("trace" => 1, "exception" => 1));
var_dump($client->__getFunctions());
//die();
$result = $client->getList('ani');
var_dump($result);
} catch (SoapFault $e) {
var_dump($e);
}
die();
}
}
但是,当我从导航器中调用此链接时: http://localhost/stackoverflower/test-list
我的导航器总是向我显示: 请!我需要帮助!因为我看到我的客户端找到了WSDL的功能,但是我不理解此错误...未找到。...