我在PHP中使用SoapClient和我有一個小項目的小問題。肥皂PHP請求與登錄標題
我有以下WSDL
提出要求usernae /密碼SOAP
頭:
https://www1.gsis.gr/webtax2/wsgsis/RgWsPublic/RgWsPublicPort?WSDL
的說明說我必須對SOAP頭通過用戶名和密碼這樣的:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="http://gr/gsis/rgwspublic/RgWsPublic.wsdl"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <env:Header> <ns1:Security> <ns1:UsernameToken> <ns1:Username>XXXXXXXXXXXXX</ns1:Username> <ns1:Password>YYYYYYYYYYY</ns1:Password> </ns1:UsernameToken> </ns1:Security> </env:Header>
<env:Body>
<ns:rgWsPublicVersionInfo/>
</env:Body>
</env:Envelope>
我使用以下。我嘗試了幾十種不同的方法,但沒有運氣!
$options = array ('trace' => true, 'exceptions' => true, 'connection_timeout' => 5, 'Username' => 'XXXXXXX', 'Password' => 'XXXXXXX');
$client = new SoapClient("https://www1.gsis.gr/webtax2/wsgsis/RgWsPublic/RgWsPublicPort?WSDL",$options);
$params['afmCalledFor'] = 'XXXXXX';
$params['afmCalledBy'] = 'XXXXXX';
$result = $client->rgWsPublicAfmMethod($params);
print_r($result);
...,我總是得到錯誤RG_WS_PUBLIC_TOKEN_USERNAME_NOT_DEFINED
預先感謝您的幫助:)。
亞歷
解歸的幫助後,我的代碼是這樣的(完整代碼):(沒有定義用戶呼叫服務)
$ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'; //Namespace of the WS.
//Body of the Soap Header.
$headerbody = array(
'UsernameToken' => array(
'Username' => '*******',
'Password' => '*******'
)
);
//Create Soap Header.
$header = new SOAPHeader($ns, 'Security', $headerbody);
$options = array ('trace' => true, 'exceptions' => true, 'connection_timeout' => 5);
$client = new SoapClient("https://www1.gsis.gr/webtax2/wsgsis/RgWsPublic/RgWsPublicPort?WSDL",$options);
//set the Headers of Soap Client.
$client->__setSoapHeaders($header);
$params['afmCalledFor'] = '**********';
$params['afmCalledBy'] = '**********';
$result = $client->rgWsPublicAfmMethod($params);
print_r($result);
我不斷收到RG_WS_PUBLIC_TOKEN_USERNAME_NOT_DEFINED。
任何幫助表示讚賞。我正處於混沌狀態。
你需要尋找到PHP的SOAPHeaders:http://php.net/manual/en/class.soapheader.php – denormalizer
我看着的SOAPHeaders但不能使它工作:( –