SOAP: процедура ‘helloRequest’ отсутствует

Я использую этот документ для создания Сервиса SOAP в Symfony: https://symfony.com/doc/2.8/controller/soap_web_service.html

Я создал тест в PHPUnit:

class SOAPServiceControllerTest extends \PHPUnit\Framework\TestCase
{

/** @test */
public function it_should_process_a_hello_soap_request()
{
// Setup SoapClient
$client = new \SoapClient(
'https://example.com/soap/1.0/SOAPService?wsdl',
[
'stream_context' => stream_context_create(
[
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
],
]
),
'cache_wsdl' => WSDL_CACHE_NONE,
'trace' => 1,
'exception' => true,
'login' => 'username',
'password' => 'password',
]
);

// Call method on SoapClient
$result = $client->hello('name');

// Assert
self::assertEquals('Hello, name', $result);
}
}

Затем я взял код из документации Symfony:

контроллер

class SOAPServiceController extends Controller
{

/**
* @Route("/1.0/SOAPService")
*/
public function index()
{
// Render wsdl with Twig
/** @var \Twig\Environment $twig */
$twig = $this->container->get('twig');
$wsdlContent = $twig->render('AppBundle:Soap:hello.xml.twig', ['domain' => 'example.com']);

// Convert wsdl content to data uri because SoapServer can not consume wsdl content as a normal string
$wsdlDataUri = 'data://text/plain;base64,'.base64_encode($wsdlContent);

// Instantiate SoapServer with wsdl
$soapServer = new \SoapServer($wsdlDataUri, ['cache_wsdl' => WSDL_CACHE_NONE]);

// Set service to handle SOAP request
$helloService = $this->container->get('hello.service');
$soapServer->setObject($helloService);

// Set response type for correct SOAP response
$response = new Response();
$response->headers->set('Content-Type', 'text/xml; charset=ISO-8859-1');

// Capture output and put it into the response object
ob_start();
$soapServer->handle();
$response->setContent(ob_get_clean());

return $response;
}
}

обслуживание

class HelloService
{

public function hello(string $name): string
{
return 'Hello, ' . $name;
}
}

И я использую этот файл WSDL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"xmlns:tns="urn:arnleadservicewsdl"xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"xmlns="http://schemas.xmlsoap.org/wsdl/"targetNamespace="urn:helloservicewsdl">

<types>
<xsd:schema targetNamespace="urn:hellowsdl">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
</xsd:schema>
</types>

<message name="helloRequest">
<part name="name" type="xsd:string" />
</message>

<message name="helloResponse">
<part name="return" type="xsd:string" />
</message>

<portType name="hellowsdlPortType">
<operation name="hello">
<documentation>Hello World</documentation>
<input message="tns:helloRequest"/>
<output message="tns:helloResponse"/>
</operation>
</portType>

<binding name="hellowsdlBinding" type="tns:hellowsdlPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="hello">
<soap:operation soapAction="urn:arnleadservicewsdl#hello" style="rpc"/>

<input>
<soap:body use="encoded" namespace="urn:hellowsdl"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>

<output>
<soap:body use="encoded" namespace="urn:hellowsdl"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>

<service name="hellowsdl">
<port name="hellowsdlPort" binding="tns:hellowsdlBinding">
<soap:address location="https://example.com/soap/1.0/SOAPService?wsdl" />
</port>
</service>
</definitions>

Тест в PHPUnit работает, но когда я отправляю запрос SOAP в формате XML, он выдает ошибку: «SOAP-ENV: ServerProcedure« helloRequest »отсутствует»

Я использовал этот запрос SOAP:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<helloRequest>
<hello>
<name>test</name>
</hello>
</helloRequest>
</soap:Body>
</soap:Envelope>

0

Решение

Мне удалось решить эту проблему с помощью вывода SOAP-запроса из теста PHPUnit.

$client->__getLastRequest(); показал, что <ns:helloRequest> узел не должен быть в запросе.

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector