PHP SoapClient and a complex header

前端 未结 2 394
没有蜡笔的小新
没有蜡笔的小新 2020-12-17 03:33

I have been trying for a while now, but I can\'t figure out how to use PHP SoapCLient in combination with a WSDL to form a complex header (that is, more complex than any tut

相关标签:
2条回答
  • 2020-12-17 03:50

    A possible way of doing this is overwriting the __doRequest function using curl. There is an example here which shows how to turn off KeepAlive.

    0 讨论(0)
  • 2020-12-17 04:01

    I had issues with this as well when implementing wsse. Here was my approach. Yes, this is quite wsse-specific; however, it should work in your context as well. Note especially how there's the 'wsse' namespace parameter in the call to new SoapHeader(). Just replace that with 'eb' for your case.

    $header_part = '
        <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext" SOAP-ENV:mustUnderstand="1">
            <wsse:UsernameToken>
                <wsse:Username>'."USERNAME".'</wsse:Username>
                <wsse:Password>'."PASSWORD".'</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    ';
    $soap_var_header = new SoapVar( $header_part, XSD_ANYXML, null, null, null );
    $soap_header = new SoapHeader( 'http://your-target-service.com', 'wsse', $soap_var_header );
    $soap_client->__setSoapHeaders($soap_header);
    

    Another solution is to mangle the XML after subclassing the SoapClient, but I'd only do this as a last resort.

    class My_SoapClient extends SoapClient {
       protected $_response = null;
       public function __doRequest( $request, $location, $action, $version, $one_way=null ) {
          // insert big bad mangling code here
          $this->_response = parent::__doRequest( $this->_request, $location, $action, $version, $one_way );
          return $this->_response;
       }
    }
    
    0 讨论(0)
提交回复
热议问题