简体   繁体   中英

How to call SOAP wsdl with header parameters in Laravel 5.3?

I use artisaninweb/laravel-soap package to run SOAP wsdl file. In order to parse WSDL file I need to call it together with header parameters. So in other words, first I need to set header parameters and then call it together with this parameters. In my laravel code it is like that:

    $customHeader1 = new SoapHeader('Accept-Encoding','gzip,deflate'); // <!-- The custom header 1
    $customHeader2 = new SoapHeader('Content-Type', 'text/xml;charset=UTF-8'); // <!-- The custom header 2
    $customHeader3 = new SoapHeader('SOAPAction', '"urn:sap-com:document:sap:soap:functions:mc-style:yws_check_fincode:YcheckFincodeRequest"'); 
    $customHeader4 = new SoapHeader('Content-Length','346');  
    $customHeader5 = new SoapHeader('Host','host');  
    $customHeader6 = new SoapHeader('Connection',' Keep-Alive');  
    $customHeader7 = new SoapHeader('User-Agent',' Apache-HttpClient/4.1.1 (java 1.5)');


           SoapWrapper::add(function ($service) use($customHeader1,$customHeader2,$customHeader3,$customHeader4,$customHeader5,$customHeader6,$customHeader7) {
              $service
              ->name('myapp')


              ->wsdl('http://wsdl_url')
              //->header($namespace,$name,$data,$mustunderstand,$actor)  
              ->customHeader($customHeader1)
              ->customHeader($customHeader2)
              ->customHeader($customHeader3)
              ->customHeader($customHeader4)
              ->customHeader($customHeader5)
              ->customHeader($customHeader6)
              ->customHeader($customHeader7)
;
});



    SoapWrapper::service('myapp', function ($service)  {
           print_r($service->getFunctions());
    });

I can perfectly call WSDL file in SOAP ui. But it does not work when I run my laravel code. My headers in SOAP UI is like that (ie below image) . How can I add these headers to my laravel code?:

在此输入图像描述

Or what is wrong with my laravel code?

$ns = ' http://namespace.example.com/ '; //Namespace of the WS.

//Body of the Soap Header. 
$headerbody = array('Accept-Encoding' => 'gzip,deflate', 
                    'Content-Type' => 'text/xml;charset=UTF-8', 
                    'SOAPAction'=> "urn:sap-com:document:sap:soap:functions:mc-style:yws_check_fincode:YcheckFincodeRequest", 
                    'Content-Length', '346',
                    'Host'=> 'host',
                    'Connection' => 'Keep-Alive',
                    'User-Agent' => ' Apache-HttpClient/4.1.1 (java 1.5)'
                    ); 

//Create Soap Header.        
$myheader = new SOAPHeader($ns, 'RequestorCredentials', $headerbody); 

SoapWrapper::add(function ($service) use($myheader) {
          $service
          ->name('myapp')
          ->wsdl('http://wsdl_url')
          ->customHeader($myheader);
});

try with this above code, have not tested with your code, it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM