Get XML Received with PHP SOAP Server

I use the built-in SOAP server in the symfony2 application and in addition to processing StdClass-Object, I will need to read the full xml obtained for debugging and logging. Is there a way to just intercept migrated xml? It should be somewhere in the request header, but I just can't find it.

+8
soap php symfony
source share
2 answers

I searched for the same and finally found it. Hope this helps you or someone else.

$postdata = file_get_contents("php://input"); 

The $postdata will have raw XML. Found through the following two links:

http://php.net/manual/en/reserved.variables.httprawpostdata.php

http://php.net/manual/en/soapserver.soapserver.php

+17
source share

The raw XML passed in the SOAP envelope must be in the body of the POST. In a Symfony application, you can get the body of a POST request by creating a Request object and calling its getContents () method.

Inside the controller

You can easily get the contents of the request in the controller, for example:

 // src/MyProject/MyBundle/Controller/MyController.php use Symfony\Component\HttpFoundation\Request; ... $request = Request::createFromGlobals(); $soapEnvelope = $request->getContents(); 

In service

Best practice (for Symfony 2.4+) is to implement RequestStack in your service class in a service container. You can do this as a constructor argument for your service class by calling the setter method, etc. Here is a quick example of using injection through a constructor.

In your service container:

 // src/MyProject/MyBundle/Resources/config/services.xml <service id="my.service" class="MyServiceClass"> <argument type="service" id="request_stack" /> </service> 

Then in your service class:

 // src/MyProject/MyBundle/Service/MyService.php use Symfony\Component\HttpFoundation\RequestStack; .... class MyServiceClass { /** * @var RequestStack $rs */ private $requestStack; /** * Constructor * * @param RequestStack $requestStack */ public function __construct(RequestStack $requestStack) { $this->requestStack = $requestStack; } /** * Some method where you need to access the raw SOAP xml */ public function myMethod() { $request = $this->requestStack->getCurrentRequest(); $soapEnvelope = $request->getContents(); } } 

Reference documentation:

http://symfony.com/blog/new-in-symfony-2-4-the-request-stack

+2
source share

All Articles