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

做~自己de王妃 提交于 2021-01-27 15:15:01

问题


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 (i.e. below image). How can I add these headers to my laravel code?:

Or what is wrong with my laravel code?


回答1:


$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.



来源:https://stackoverflow.com/questions/40762501/how-to-call-soap-wsdl-with-header-parameters-in-laravel-5-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!