src/Extension/WSAddressing.php
public function onRequest(RequestEvent $event)
    {
        if (!$this->wsaEnabled) {
            return;
        }

        $request = $event->getRequest();
        $envelope = $request->documentElement;
        $soapNS = $envelope->namespaceURI;

        $xpath = new \DOMXPath($event->getRequest());
        $xpath->registerNamespace('soap', $soapNS);
        $xpath->registerNamespace('wsa', self::NS_WSA);

        // Add WSA namespace to envelope
        $envelope->setAttributeNS(self::NS_XMLNS, 'xmlns:wsa', self::NS_WSA);

        // Find or create header
        $headers = $xpath->query('//soap:Envelope/soap:Header');
        $header = $headers->item(0);

        if (!$header) {
            $header = $request->createElementNS($soapNS, $envelope->prefix . ':Header');
            $envelope->insertBefore($header, $envelope->firstChild);
        }

        // Add MessageID
        $header->appendChild($request->createElementNS(self::NS_WSA, 'wsa:MessageID', 'uuid:' . Uuid::uuid4()));

        // Add Action
        $header->appendChild($request->createElementNS(self::NS_WSA, 'wsa:Action', $event->getAction()));

        // Add To
        $header->appendChild($request->createElementNS(self::NS_WSA, 'wsa:To', $event->getLocation()));

        // Add From
        if (false !== $this->getFrom()) {
            // use anonymous when set to true, given address otherwise
            $fromAddress = $this->getFrom() === true ? self::ANONYMOUS : $this->getFrom();
            $from = $request->createElementNS(self::NS_WSA, 'wsa:From');
            $from->appendChild($request->createElementNS(self::NS_WSA, 'wsa:Address', $fromAddress));
            $header->appendChild($from);
        }

        // Add ReplyTo
        if (!$event->isOneWay()) {
            $address = $this->address ?: self::ANONYMOUS;

            $replyTo = $request->createElementNS(self::NS_WSA, 'wsa:ReplyTo');
            $replyTo->appendChild($request->createElementNS(self::NS_WSA, 'wsa:Address', $address));

            $header->appendChild($replyTo);
        }
    }
public function onRequest(RequestEvent $event)
    {
        if (!$this->wsaEnabled) {
            return;
        }

        $request = $event->getRequest();
        $envelope = $request->documentElement;
        $soapNS = $envelope->namespaceURI;

        $xpath = new \DOMXPath($event->getRequest());
        $xpath->registerNamespace('soap', $soapNS);
        $xpath->registerNamespace('wsa', self::NS_WSA);

        // Add WSA namespace to envelope
        $envelope->setAttributeNS(self::NS_XMLNS, 'xmlns:wsa', self::NS_WSA);

        // Find or create header
        $headers = $xpath->query('//soap:Envelope/soap:Header');
        $header = $headers->item(0);

        if (!$header) {
            $header = $request->createElementNS($soapNS, $envelope->prefix . ':Header');
            $envelope->insertBefore($header, $envelope->firstChild);
        }

        // Add MessageID
        $header->appendChild($request->createElementNS(self::NS_WSA, 'wsa:MessageID', 'uuid:' . Uuid::uuid4()));

        // Add Action
        $header->appendChild($request->createElementNS(self::NS_WSA, 'wsa:Action', $event->getAction()));

        // Add To
        $header->appendChild($request->createElementNS(self::NS_WSA, 'wsa:To', $event->getLocation()));

        // Add From
        if (false !== $this->getFrom()) {
            // use anonymous when set to true, given address otherwise
            $fromAddress = $this->getFrom() === true ? self::ANONYMOUS : $this->getFrom();
            $from = $request->createElementNS(self::NS_WSA, 'wsa:From');
            $from->appendChild($request->createElementNS(self::NS_WSA, 'wsa:Address', $fromAddress));
            $header->appendChild($from);
        }

        // Add ReplyTo
        if (!$event->isOneWay()) {
            $address = $this->address ?: self::ANONYMOUS;

            $replyTo = $request->createElementNS(self::NS_WSA, 'wsa:ReplyTo');
            $replyTo->appendChild($request->createElementNS(self::NS_WSA, 'wsa:Address', $address));

            $header->appendChild($replyTo);
        }
    }
public function onRequest ( RequestEvent $ event ) { if ( ! $ this -> wsaEnabled ) { return ; } $ request = $ event -> getRequest ( ) ; $ envelope = $ request -> documentElement ; $ soapNS = $ envelope -> namespaceURI ; $ xpath = new \ DOMXPath ( $ event -> getRequest ( ) ) ; $ xpath -> registerNamespace ( 'soap' , $ soapNS ) ; $ xpath -> registerNamespace ( 'wsa' , self :: NS_WSA ) ; // Add WSA namespace to envelope $ envelope -> setAttributeNS ( self :: NS_XMLNS , 'xmlns:wsa' , self :: NS_WSA ) ; // Find or create header $ headers = $ xpath -> query ( '//soap:Envelope/soap:Header' ) ; $ header = $ headers -> item ( 0 ) ; if ( ! $ header ) { $ header = $ request -> createElementNS ( $ soapNS , $ envelope -> prefix . ':Header' ) ; $ envelope -> insertBefore ( $ header , $ envelope -> firstChild ) ; } // Add MessageID $ header -> appendChild ( $ request -> createElementNS ( self :: NS_WSA , 'wsa:MessageID' , 'uuid:' . Uuid :: uuid4 ( ) ) ) ; // Add Action $ header -> appendChild ( $ request -> createElementNS ( self :: NS_WSA , 'wsa:Action' , $ event -> getAction ( ) ) ) ; // Add To $ header -> appendChild ( $ request -> createElementNS ( self :: NS_WSA , 'wsa:To' , $ event -> getLocation ( ) ) ) ; // Add From if ( false !== $ this -> getFrom ( ) ) { // use anonymous when set to true, given address otherwise $ fromAddress = $ this -> getFrom ( ) === true ? self :: ANONYMOUS : $ this -> getFrom ( ) ; $ from = $ request -> createElementNS ( self :: NS_WSA , 'wsa:From' ) ; $ from -> appendChild ( $ request -> createElementNS ( self :: NS_WSA , 'wsa:Address' , $ fromAddress ) ) ; $ header -> appendChild ( $ from ) ; } // Add ReplyTo if ( ! $ event -> isOneWay ( ) ) { $ address = $ this -> address ? : self :: ANONYMOUS ; $ replyTo = $ request -> createElementNS ( self :: NS_WSA , 'wsa:ReplyTo' ) ; $ replyTo -> appendChild ( $ request -> createElementNS ( self :: NS_WSA , 'wsa:Address' , $ address ) ) ; $ header -> appendChild ( $ replyTo ) ; } }
Add WS-Addressing headers to the request

@param RequestEvent $event
@return void
Add WS - Addressing headers to the request