ws-security и nusoap не работают - PullRequest
0 голосов
/ 23 марта 2011

Для проекта мне нужно связаться с веб-сервисом другой компании. Они сделали это на Soap, и все это подробно описано и т. Д. Я узнал переменные и типы и какой метод и т. Д.

Они также заявили, что я должен использовать WS-security с pwd и именем пользователя в заголовках.

Итак, я сделал это с помощью nusoap:

<code>require_once('../lib/nusoap.php');
$client = new nusoap_client("http://webservice.client.com/cir.asmx?WSDL", 'wsdl');
$err = $client->getError();
if ($err) {
    echo '<h2>Constructor error</h2><pre>' . $err . '
'; } $ client-> soap_defencoding = 'UTF-8'; $ result = $ client-> call ('GetLastUpdate'); // Проверка на неисправность if ($ client-> fault) { echo '

Fault

';
    print_r($result);
    echo '
'; } еще { // Проверка на ошибки $ err = $ client-> getError (); if ($ err) { // Показать ошибку echo '

Ошибка

' . $err . '
'; } еще { // Показать результат echo '

Результат

';
        print_r($result);
        echo '
'; } } echo '

Request

' . htmlspecialchars($client->request, ENT_QUOTES) . '
'; echo '

Response

' . htmlspecialchars($client->response, ENT_QUOTES) . '
'; echo '

Debug

' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '
';

тогда я добавил:

$client->setCredentials('******','*******','basic');

, который не работал, поэтому я посмотрел стиль ws-security и добавил вместо него следующее:

$auth='<wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
    <wsse:Username>********</wsse:Username>
    <wsse:Password Type="wsse:PasswordText">*******</wsse:Password>
    <wsse:Nonce>'.base64_encode(pack('H*',$nonce)).'</wsse:Nonce>
    <wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">'.time().'</wsu:Created>
   </wsse:UsernameToken>
</wsse:Security>';

$client->setHeaders($auth);

Что тоже не сработало ... они выдают ту же ошибку .... вот что она возвращает:

Fault

Array
(
    [faultcode] => q0:Security
    [faultstring] => Header http://schemas.xmlsoap.org/ws/2004/08/addressing:Action for ultimate recipient is required but not present in the message.
    [faultactor] => http://webservice.client.com/cir.asmx
)
Request

POST /cir.asmx HTTP/1.0
Host: webservice.client.com
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "http://www.client.com/namespaces/cir01/GetLastUpdate"
Content-Length: 967

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2278="http://tempuri.org"><SOAP-ENV:Header><wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
    <wsse:Username>*******</wsse:Username>
    <wsse:Password Type="wsse:PasswordText">********</wsse:Password>
    <wsse:Nonce></wsse:Nonce>
    <wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">1300862463</wsu:Created>
   </wsse:UsernameToken>
</wsse:Security></SOAP-ENV:Header><SOAP-ENV:Body><GetLastUpdate xmlns="http://www.client.com/namespaces/cir01"></GetLastUpdate></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response

HTTP/1.1 500 Internal Server Error
Connection: close
Date: Wed, 23 Mar 2011 06:39:57 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Content-Length: 1421

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><soap:Header><wsa:Action>http://schemas.xmlsoap.org/ws/2004/08/addressing/fault</wsa:Action><wsa:MessageID>urn:uuid:b8c93511-b6e6-4247-9ab5-65bd4a6aa286</wsa:MessageID><wsa:RelatesTo>urn:uuid:6dfa917b-3163-4ae9-bd84-0855b7a1329e</wsa:RelatesTo><wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To><wsse:Security><wsu:Timestamp wsu:Id="Timestamp-4d37a6a5-9445-40d6-8660-a724999cc3bc"><wsu:Created>2011-03-23T06:39:57Z</wsu:Created><wsu:Expires>2011-03-23T06:44:57Z</wsu:Expires></wsu:Timestamp></wsse:Security></soap:Header><soap:Body><soap:Fault><faultcode xmlns:q0="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">q0:Security</faultcode><faultstring>Header http://schemas.xmlsoap.org/ws/2004/08/addressing:Action for ultimate recipient is required but not present in the message.</faultstring><faultactor>http://webservice.client.com/cir.asmx</faultactor></soap:Fault></soap:Body></soap:Envelope>

1 Ответ

0 голосов
/ 24 мая 2011

Пожалуйста, попробуйте установить заголовок, используя следующий метод:

$client = new SoapClient("Wsdl_URL", array("trace" => 0)); 

$WSHeader = array(
    "UsernameToken"=>array(
        "Username"=>"YourUserName",
        "Password"=>"YourPassword",
    )
);

$header[] = new
SoapHeader("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security",$WSHeader);

$client->__setSoapHeaders($header);

$REsponse = $client->YourRequest();
...