【问题标题】:Response from soap header来自soap标头的响应
【发布时间】:2015-06-22 17:32:06
【问题描述】:

尽管我对 php soap 概念很陌生,但我还是编写了一个程序来使用 SoapClient 与 Web 服务器通信。

这是我的 wsdl 链接: https://es.adpolice.gov.ae/TrafficInsurance/TrafficInsuranceServicesNew.asmx?wsdl

服务名称:CreateVehicleInsurancePolicy 链接:https://es.adpolice.gov.ae/TrafficInsurance/TrafficInsuranceServicesNew.asmx?op=CreateVehicleInsurancePolicy

我将我的程序托管在经过 ssl 认证的托管中。当它运行时,它会在soap body 响应(lngSerial)中生成响应。我想打印来自soap 标头的响应值( SoapHeaderOut)。

即intResponseCode,strArMsg,strEnMsg。

请指导我。下面我提供我正在使用的脚本。

<?php
ini_set("soap.wsdl_cache_enabled", "0");
ini_set("soap.wsdl_cache_ttl", "0");
class SOAPStruct
{
    function __construct($user, $pass) 
    {
        $this->userName = $user;
        $this->Password = $pass;

    }
}

$service = new SoapClient("https://es.adpolice.gov.ae/TrafficInsurance/TrafficInsuranceServicesNew.asmx?wsdl");
$auth = new SOAPStruct('username','password');
$header = new SoapHeader("http://adpolice.gov.ae/TrafficInsurance/TrafficInsuranceServices.asmx","SoapHeaderIn",$auth,true); 
$service->__setSoapHeaders($header); 
$param = array('lngInsuranceCompanyCode'=> '1','intInsuranceKindCode'=>'1','lngTcf'=>'3070858641','strPolicyNo'=>'1055385883','dtExpiryDate'=>'2016-04-30T00:00:00','dtStartDate'=>'2015-03-31T00:00:00','strChassisNo'=>'6T1BE42RG465465','strRemarks'=>'demo','strUserCreated'=>'demo');

$response = $service->CreateVehicleInsurancePolicy($param)->CreateVehicleInsurancePolicyResult;

 foreach ($response as $record) {
    print_r($record);
    print_r("<br>");
  }

?>

【问题讨论】:

    标签: php web-services soap web wsdl


    【解决方案1】:

    根据 PHP 文档,您应该能够通过使用低级 API 而不是 WSDL 提供的魔术方法来访问 SoapHeader 响应对象。在你的情况下,它会是

    $response = $service->__soapCall("CreateVehicleInsurancePolicy", $param, null, $headers, $response_headers);
    

    应该将您想要的对象存储到 $response_headers 变量中。

    旧响应:(与响应的实际 HTTP 标头有关) 如果您使用这样的跟踪集实例化 SoapClient:

    $service = new SoapClient("https://es.adpolice.gov.ae/TrafficInsurance/TrafficInsuranceServicesNew.asmx?wsdl", array("trace" => 1))
    

    您应该能够使用SoapClient::__getLastResponseHeaders 获得标头响应

    $response_headers = $service->__getLastResponseHeaders();
    

    【讨论】:

    • **$response_headers = $service->__getLastResponseHeaders(); var_dump($response_headers); ** 它像 string(229) "HTTP/1.1 200 OK Cache-Control: private, max-age=0 Content-Length: 1117 Content-Type: text/xml; charset=utf-8 Server: Microsoft-IIS/ 7.5 X-AspNet 版本:2.0.50727 X-Powered-By:ASP.NET 日期:2015 年 4 月 16 日星期四 12:48:55 GMT “。我应该如何获得 3 标头元素值。
    • 我更新了我的答案。我原来的只是处理 HTTP 标头。如果你使用 __soapCall 你可以获得响应头,即使它不如纯 WSDL 模式代码漂亮
    • 再次相同的响应即将到来..实际上我对这件事很陌生..所以你能写下那个标题响应脚本吗..实际上我尝试了很多天。
    猜你喜欢
    • 2016-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 2012-08-14
    • 1970-01-01
    相关资源
    最近更新 更多