php - 如何在 Laravel 5.3 中使用 header 参数调用 SOAP wsdl?

标签 php web-services laravel soap wsdl

我使用 artisaninweb/laravel-soap 包来运行 SOAP wsdl 文件。为了解析 WSDL 文件,我需要将它与 header 参数一起调用。所以换句话说,首先我需要设置 header 参数,然后将其与此参数一起调用。 在我的 laravel 代码中是这样的:

    $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());
    });

我可以在 SOAP ui 中完美调用 WSDL 文件。但是当我运行我的 laravel 代码时它不起作用。 我在 SOAP UI 中的 header 就像那样(即下图)。如何将这些 header 添加到我的 Laravel 代码中?:

enter image description here

或者我的 laravel 代码有什么问题?

最佳答案

$ns = ' http://namespace.example.com/ ';//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);
});

尝试使用上面的代码,尚未使用您的代码进行测试,它应该可以工作。

关于php - 如何在 Laravel 5.3 中使用 header 参数调用 SOAP wsdl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40762501/

相关文章:

database - RESTful URI 是否应该公开数据库主键?

.net - WSDL 未定义时如何传递 Soap header ?

php - 如何显示可读数组 - Laravel

php - 让 XHProf 可视化(Graphviz 和 dot 的问题)正常工作

php - 使用 PS (postscript) 文件将转义码打印到打印机

c# - WCF REST 和 QueryString,错误的 UriTemplate?

php - 在 Laravel 的 Homestead 中运行 PHPUnit

php - Laravel/Heroku,没有这样的文件或目录用于 session

php - 如何简化这个PHP条件语句?

php - 如何修复使用 PHP 计算纯文本字数的错误?