How to send this Header using NUSoap PHP?

0

I'm trying to authenticate in a WS but I can not connect, and I can connect and generate a token, but when trying to do other operations with a token I can not fill the header and validate the session, see the herader excerpt:

    <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <Autenticacao xmlns="servidoralvo.com.br/OperacoesPortador">
      <Token>string</Token>
    </Autenticacao>
  </soap:Header>
  <soap:Body>
    <CartoesPortador xmlns="servidoralvo.com.br/OperacoesPortador">
      <request>
        <DocumentoPortador>string</DocumentoPortador>
      </request>
    </CartoesPortador>
  </soap:Body>
</soap:Envelope>

I'm trying the following:

$Header = '
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <Autenticacao xmlns="servidoralvo.com.br/OperacoesPortador">
      <Token>' . $Token . '</Token>
    </Autenticacao>
  </soap:Header>
</soap:Envelope>';

$AHeader = $Client->setHeaders($Header);

$AParams = array();
$AParams["request"]["DocumentoPortador"] = "14238911996";

$Conexao = $Client->Call("CartoesPortador", array($AParams), '', '', true, true);

fPrintDebug($Conexao);

It gives authentication error, but it is not the token, the error is in the header construction, because that same token using the native PHP Soap works.

The detail is that on the server that I use on the web, there is no way to enable native Soap so I have to use NuSoap PHP

Would anyone have a clue what it could be?

    
asked by anonymous 06.07.2016 / 16:07

2 answers

0

First you create a file that will contain your SOAP instructions such as server.php.

Within this file you must first have this

<?php
//Chama a lib
require_once "lib/nusoap.php";
//Starta o Objeto
$server = new soap_server();
//Diz que ele tem que criar um wsdl ou XML
$server->configureWSDL("registerWithToken", "registerWithToken");

Now in this same file you will record the methods available in your XML.

$server->register("registerWithToken.generateToken",
    array("token" => "xsd:string"),
    array('return' => 'xsd:string'
    ),
    'urn:registerWithToken',
    'urn:registerWithToken',
    'rpc',
    'encoded',
    'Gera o token de login'
    );

In the class with the method.

     class registerWithToken {
        public function generateToken() {
            ... Código que gera e retorna o Token ...
            }
     }

And put in the end ..

$HTTP_RAW_POST_DATA = (isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : 'teste');
$server->service($HTTP_RAW_POST_DATA);

In this example, only one method follows an example with more methods. And with more information.

It will create a record of methods like this - > link And an XML like that - > link

Consumption can be done in several ways the example that creates the above file is this: link

    
06.07.2016 / 18:09
0

Personal simple thing that consumed me a lot of time, but what I'm going to consume in WS rsrs, the header has to go like this:

$Header = '<Autenticacao xmlns="' . PORTNAMES . '"><Token>' . $Token . '</Token></Autenticacao>';

What a thing!

    
06.07.2016 / 20:13