PHP SoapClient and a complex header

前端 未结 2 400
没有蜡笔的小新
没有蜡笔的小新 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 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 = '
        
            
                '."USERNAME".'
                '."PASSWORD".'
            
        
    ';
    $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;
       }
    }
    

提交回复
热议问题