How to upload this Header using Nusoap PHP?

Asked

Viewed 1,128 times

0

Guys I’m trying to authenticate in a WS but I’m not getting it, I can connect and generate a token, but when trying to do other operations with token received I can’t fill the header and validate the session, see the section of herader:

    <?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 header construction, because this same token using native PHP Soap works.

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

Someone would have a hint of what might be?

  • Marcelo Voce wants to create the wsdl directly from XML ? For the right reason using Nusoap is to use the configureWSDL method that is inside the $Soap_server object... If that’s what it is, explain to me and I’ll send you an example.

  • Check it out, I did some tests with the native PHP Soap, but when I put it on the server I saw that there is no Soap, the server uses a include method, well I went to use the server method and gave some pauses because it is outdated, so not to have to be asked to the provider update the server, I’m trying to use nuSoap, I can authenticate well, but when having to use the functions that require the Token it does not validate the header... I’m not sure how to send the complete request, as I put in the xml above I have to send the header and the body, but by Soap I do not know how to do.

  • Got it guy in Nusoap if you do not create the WSDL or XML as you are doing you create a method and records it the XML is generated by Nusoap in this case you need to put the method that creates the token and register it. Follow a CRUD I made with Nusoap, I still need to refactor but I’m sure it will help you. https://github.com/satodu/Nusoap-sample. After you register, just go to http://localhost? wsdl

  • I’ll post an answer to see if it helps you

2 answers

0

First Voce creates a file that will contain your SOAP instructions such as server.php.

Inside that file first you have to 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 even in this same file you will register 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 it is only for a method follows an example with more methods. And with more information.

It will create a record of such methods -> http://papoinformal.com.br/prueba/2/new/server.php And an XML like that -> http://papoinformal.com.br/prueba/2/new/server.php?wsdl

Consumption can be done in several ways the example that creates the above file is this : https://github.com/satodu/Nusoap-sample/blob/master/server.php

  • Um... I think I was unhappy in my text, it seems to me that they understood that I want to create a server, but in fact I just want to consume an existing WS.

  • kkk. Cara Soap Client is native and tried to put $client = new Soapclient('http://papoinformal.com.br/prueba/2/new/server.php?wsdl'); ??

  • https://github.com/satodu/Nusoap-sample/blob/master/service.php Check out the other Nusoap consumption

  • Because @Dom Soap is native, but I don’t know what happens to some Tis... because the guy doesn’t install PHP Soap on a server at a time when everyone uses it? I don’t understand... on the server I’m using just doesn’t have Soap Native... the guy must have his reasons. I have to use Nusoap, :(

  • Look at this second example that I put consumption via nusoap

  • So @Dom, I can consume WS what I’m not getting is to send the Header which is where I send the Token, then the server refuses.

Show 1 more comment

0


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

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

What a thing!

  • 1

    Ola @Marcelo, since this is the answer to your problem, mark it as correct/accepted by clicking on the " " that is next to it, which also marks your question as solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.