问题
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