[英]Adding a SOAP header with PHP and wsdl2php
我是PHP編程的完全新手,但我的任務是編寫一個示例PHP Web服務客戶端,它使用我公司用Java編寫的Web服務。 我們有兩種類型的服務。 需要身份驗證的人和不需要身份驗證的人。 我已經使用wsdl2php庫成功地與不需要身份驗證的服務進行通信。 我們的安全服務要求我在我的請求中添加一個SOAP標頭,如下所示:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sen="https://webservices.averittexpress.com/SendWebImageService">
<soapenv:Header xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns:authnHeader soapenv:mustUnderstand="0" xmlns:ns="http://webservices.averittexpress.com/authn">
<Username>xxxxxxxx</Username>
<Password>xxxxxxxx</Password>
</ns:authnHeader>
</soapenv:Header>
我遇到的問題是我不知道如何使用wsdl2php或者甚至是可能的。 這是我目前用來測試的PHP文件。
<?php
require_once 'LTLRateQuoteService.php';
$rqs = new LTLRateQuoteService();
$info = new ShipmentInfo();
$HeaderSecurity = array("authnHeader"=>array("UserName"=>"xxxxxx",
"Password"=>"xxxxxx",));
$header[] = new SoapHeader("http://schemas.xmlsoap.org/soap/encoding",
"Header",$HeaderSecurity);
$rqs->__setSoapHeaders($header);
$args = new AvtLTLRateQuoteRequest();
$args->AccountNumber = '1234578';
$args->OriginCity = 'Cookeville';
$args->OriginState = 'TN';
$args->OriginZip = '38501';
$args->DestinationCity = 'Morristown';
$args->DestinationState = 'TN';
$args->DestinationZip = '37814';
$args->ShipDate = '12/12/2011';
$args->Customer = 'S';
$args->PaymentType = 'P';
$info->NumPieces = '1';
$info->NumHandling = '1';
$info->CubicFeet = '1';
$info->Items = '1';
$info->TotalItem = '1';
$info->TotalWeight = '100';
$args->ShipmentInfo = $info;
$grq = new getLTLRate();
$grq->arg0 = $args;
$response = $rqs->getLTLRate($grq);
$details = $response->return;
print 'Total Freight Charge: ' . $details->TotalFreightCharge . ' ';
?>
我需要以某種方式將用戶名和密碼附加到此請求的標頭上,並且不知道如何操作。 我看了wsdl2php網站,關於如何使用該庫的文檔方面很少。 任何幫助,將不勝感激。
謝謝,
安德魯
如果沒有答案,不要聆聽粗魯的評論巨魔,只有侮辱。 這是我怎么做的。
function __construct($url='wsdl url')
{
$auth=array('AccountUsername'=>'test','AccountPW'=>'test');
$authvalues = new \SoapVar($auth, SOAP_ENC_OBJECT);
$header = new \SoapHeader('http://www.nsurl.com/',
'AuthenticationHeader', // Rename this to the tag you need
$authvalues, false);
$this->soapClient = new SoapClient($url,array("classmap"=>self::$classmap,"trace" => true,"exceptions" => true));
$this->soapClient->__setSoapHeaders(array($header));
//set the Headers of Soap Client.
//$this->soapClient->__setSoapHeaders($header);
}
而不是使用wsdl2php,使用PHP的內部SOAP功能會更好嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.