如何在Laravel 5.3中使用标头参数调用SOAP wsdl? [英] How to call SOAP wsdl with header parameters in Laravel 5.3?

查看:105
本文介绍了如何在Laravel 5.3中使用标头参数调用SOAP wsdl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 artisaninweb/laravel-soap 包运行SOAP wsdl文件.为了解析WSDL文件,我需要将其与标头参数一起调用.因此,换句话说,我首先需要设置标头参数,然后将其与此参数一起调用.在我的laravel代码中,就像这样:

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

我可以在SOAP ui中完美地调用WSDL文件.但是,当我运行laravel代码时,它不起作用.我在SOAP UI中的标题就像(即图片下方).如何将这些标头添加到我的laravel代码中?:

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?:

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

Or what is wrong with my laravel code?

推荐答案

$ ns =' http://namespace.example.com/';//WS的命名空间.

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

这篇关于如何在Laravel 5.3中使用标头参数调用SOAP wsdl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆