PHP soapClient send custom XML

后端 未结 2 506
旧巷少年郎
旧巷少年郎 2021-01-05 20:48

I\'m trying to make a SOAP request using soapClient class from PHP that\'s my code:

$xmlstr = <<

        
2条回答
  •  爱一瞬间的悲伤
    2021-01-05 21:18

    There is nothing like make an question to find the answer. I extended the SoapClient class and, in this way, I send the correct XML. That's the code:

    /**
     * Extend SoapClientClass
     */
    class anotherSoapClient extends SoapClient {
    
        function __construct($wsdl, $options) {
            parent::__construct($wsdl, $options);
            $this->server = new SoapServer($wsdl, $options);
        }
        public function __doRequest($request, $location, $action, $version) { 
            $result = parent::__doRequest($request, $location, $action, $version); 
            return $result; 
        } 
        function __anotherRequest($call, $params) {
            $location = 'http://localhost:8090/mockCustomerManagementSoapHttpBinding';
            $action = 'http://localhost:8090/mockCustomerManagementSoapHttpBinding/'.$call;
            $request = $params;
            $result =$this->__doRequest($request, $location, $action, '1');
            return $result;
        } 
    }
    
    // Create new SOAP client
    $wsdl = 'http://localhost:8090/mockCustomerManagementSoapHttpBinding?WSDL';
    $client = new anotherSoapClient($wsdl, array(
        'cache_wsdl'    => WSDL_CACHE_NONE, 
        'cache_ttl'     => 86400, 
        'trace'         => true,
        'exceptions'    => true,
    ));
    
    // Make the request
    try {
        $request = $client->__anotherRequest('getCustomerInfo', $XMLrequest);
    } catch (SoapFault $e ){
        echo "Last request:
    " . htmlentities($client->__getLastRequest()) . "
    "; exit(); } header('Content-type: text/xml'); echo $request;

    I use the free version of SOAP_UI to test the response.

提交回复
热议问题