Add xmlns value to Symfony2 SoapServer response

We have built a SOAP Service to receive a request however the response given needs to include an additional value and we don’t know how to add it.

We need to add xmlns="" into this: <SOAP-ENV:PrintLocationResponse> so that it reads like this <SOAP-ENV:PrintLocationResponse xmlns="">

The SOAP Service receives this request:

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="">
        <PrintLocation xmlns="" xmlns:i="">
                [ some message goes here]

The SOAP Service responds with this:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="">
                Message contents goes here

We need to add xmlns="" to this part of the response: <SOAP-ENV:PrintLocationResponse> so that the response will be like this:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="">
        <SOAP-ENV:PrintLocationResponse xmlns="">
                Message contents goes here

We do not know how to add xmlns="" into the above response.

The controller managing the request and returning the response is as follows:

    public function indexAction(Request $request)

        $soapServer = new SoapServer('wsdl/hello.wsdl');

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


        return $response;


This $soapServer = new SoapServer('wsdl/hello.wsdl'); calls the hello.wsdl which looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
             xmlns:SOAP-ENV = ""

    <wsdl:message name="helloIn">
        <part name="alertMsg" type="xsd:string" />

    <wsdl:message name="helloOut">
        <part name="PrintLocationResult" type="xsd:string" />

    <wsdl:portType name="hellowsdlPortType">
        <wsdl:operation name="PrintLocation">
            <wsdl:input message="tns:helloIn"/>
            <wsdl:output message="tns:helloOut"/>

    <wsdl:binding name="hellowsdlBinding" type="tns:hellowsdlPortType">
        <soap:binding style="rpc" transport=""/>
        <wsdl:operation name="PrintLocation">

            <soap:operation soapAction="" style="rpc"/>

                <soap:body use="literal" />
                <soap:body use="literal" />


    <wsdl:service name="hellowsdl">
        <wsdl:port name="hellowsdlPort" binding="tns:hellowsdlBinding">
            <soap:address location="http://backoffice.system/soap" />

The above WSDL is a bit of a mystery for us. We amended the example found here:

This $soapServer->setObject($this->get('hello_service')); calls HelloService.php which looks like this:

class HelloService
     * @var EntityManager
    private $entityManager;

    public function __construct(EntityManager $entityManager)
        $this->entityManager = $entityManager;

    public function PrintLocation($msg)
        $log = new TempIressMsgThree($msg);
        $xml = simplexml_load_string($log->getMsg());
        $json = json_encode($xml);
        $array = json_decode($json,TRUE);

        $xml='<?xml version="1.0" encoding="UTF-8"?>
                <message xmlns:xsd="" xmlns:xsi="" xmlns="">
                       Response message contents goes here.

        return $xml;

Can anyone help?

To clarify, we need to add xmlns="" into this: <SOAP-ENV:PrintLocationResponse> so that it reads like this <SOAP-ENV:PrintLocationResponse xmlns="">

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *