我在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但不能使它工作:( –