I cannot return Web Service value to PHP

Asked

Viewed 202 times

0

I have tested the web service through Soapui and it is working normally returning the values.

XML of the web service

    This XML file does not appear to have any style information associated with it. The document tree is shown below.
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ax213="http://appvendas.sata.com.br/xsd" xmlns:ax211="http://sql.java/xsd" xmlns:ns="http://appvendas.sata.com.br" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://appvendas.sata.com.br">
<wsdl:documentation>Please Type your service description here</wsdl:documentation>
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://sql.java/xsd">
<xs:complexType name="SQLException">
<xs:sequence>
<xs:element minOccurs="0" name="SQLState" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="errorCode" type="xs:int"/>
<xs:element minOccurs="0" name="nextException" nillable="true" type="ax211:SQLException"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:ax214="http://appvendas.sata.com.br/xsd" xmlns:ax212="http://sql.java/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://appvendas.sata.com.br">
<xs:import namespace="http://sql.java/xsd"/>
<xs:import namespace="http://appvendas.sata.com.br/xsd"/>
<xs:element name="UsuarioDAOSQLException">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="SQLException" nillable="true" type="ax212:SQLException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="efetuarLogin">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="login" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="senha" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="efetuarLoginResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="ax214:Usuario"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="selUsuario">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="idOrdemCompra" type="xs:int"/>
<xs:element minOccurs="0" name="login" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="senha" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="selUsuarioResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="ax214:Usuario"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="inserirUsuario">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="usuario" nillable="true" type="ax214:Usuario"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="inserirUsuarioResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="attUsuario">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="usuario" nillable="true" type="ax214:Usuario"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="attUsuarioResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="excluirUsuario">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="id" type="xs:int"/>
<xs:element minOccurs="0" name="login" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="senha" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="excluirUsuarioResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://appvendas.sata.com.br/xsd">
<xs:complexType name="Infos">
<xs:sequence>
<xs:element minOccurs="0" name="bairro" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="canc" type="xs:int"/>
<xs:element minOccurs="0" name="celular" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="complemento" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="conc" type="xs:int"/>
<xs:element minOccurs="0" name="cp" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="email" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="id" type="xs:int"/>
<xs:element minOccurs="0" name="idCidadeFK" type="xs:int"/>
<xs:element minOccurs="0" name="nome" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="numero" type="xs:int"/>
<xs:element minOccurs="0" name="reputacao" type="xs:double"/>
<xs:element minOccurs="0" name="rua" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="telefone" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Usuario">
<xs:complexContent>
<xs:extension base="ax213:Infos">
<xs:sequence>
<xs:element minOccurs="0" name="login" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="senha" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="efetuarLoginRequest">
<wsdl:part name="parameters" element="ns:efetuarLogin"/>
</wsdl:message>
<wsdl:message name="efetuarLoginResponse">
<wsdl:part name="parameters" element="ns:efetuarLoginResponse"/>
</wsdl:message>
<wsdl:message name="UsuarioDAOSQLException">
<wsdl:part name="parameters" element="ns:UsuarioDAOSQLException"/>
</wsdl:message>
<wsdl:message name="attUsuarioRequest">
<wsdl:part name="parameters" element="ns:attUsuario"/>
</wsdl:message>
<wsdl:message name="attUsuarioResponse">
<wsdl:part name="parameters" element="ns:attUsuarioResponse"/>
</wsdl:message>
<wsdl:message name="excluirUsuarioRequest">
<wsdl:part name="parameters" element="ns:excluirUsuario"/>
</wsdl:message>
<wsdl:message name="excluirUsuarioResponse">
<wsdl:part name="parameters" element="ns:excluirUsuarioResponse"/>
</wsdl:message>
<wsdl:message name="selUsuarioRequest">
<wsdl:part name="parameters" element="ns:selUsuario"/>
</wsdl:message>
<wsdl:message name="selUsuarioResponse">
<wsdl:part name="parameters" element="ns:selUsuarioResponse"/>
</wsdl:message>
<wsdl:message name="inserirUsuarioRequest">
<wsdl:part name="parameters" element="ns:inserirUsuario"/>
</wsdl:message>
<wsdl:message name="inserirUsuarioResponse">
<wsdl:part name="parameters" element="ns:inserirUsuarioResponse"/>
</wsdl:message>
<wsdl:portType name="UsuarioDAOPortType">
<wsdl:operation name="efetuarLogin">
<wsdl:input message="ns:efetuarLoginRequest" wsaw:Action="urn:efetuarLogin"/>
<wsdl:output message="ns:efetuarLoginResponse" wsaw:Action="urn:efetuarLoginResponse"/>
<wsdl:fault message="ns:UsuarioDAOSQLException" name="UsuarioDAOSQLException" wsaw:Action="urn:efetuarLoginUsuarioDAOSQLException"/>
</wsdl:operation>
<wsdl:operation name="attUsuario">
<wsdl:input message="ns:attUsuarioRequest" wsaw:Action="urn:attUsuario"/>
<wsdl:output message="ns:attUsuarioResponse" wsaw:Action="urn:attUsuarioResponse"/>
<wsdl:fault message="ns:UsuarioDAOSQLException" name="UsuarioDAOSQLException" wsaw:Action="urn:attUsuarioUsuarioDAOSQLException"/>
</wsdl:operation>
<wsdl:operation name="excluirUsuario">
<wsdl:input message="ns:excluirUsuarioRequest" wsaw:Action="urn:excluirUsuario"/>
<wsdl:output message="ns:excluirUsuarioResponse" wsaw:Action="urn:excluirUsuarioResponse"/>
<wsdl:fault message="ns:UsuarioDAOSQLException" name="UsuarioDAOSQLException" wsaw:Action="urn:excluirUsuarioUsuarioDAOSQLException"/>
</wsdl:operation>
<wsdl:operation name="selUsuario">
<wsdl:input message="ns:selUsuarioRequest" wsaw:Action="urn:selUsuario"/>
<wsdl:output message="ns:selUsuarioResponse" wsaw:Action="urn:selUsuarioResponse"/>
<wsdl:fault message="ns:UsuarioDAOSQLException" name="UsuarioDAOSQLException" wsaw:Action="urn:selUsuarioUsuarioDAOSQLException"/>
</wsdl:operation>
<wsdl:operation name="inserirUsuario">
<wsdl:input message="ns:inserirUsuarioRequest" wsaw:Action="urn:inserirUsuario"/>
<wsdl:output message="ns:inserirUsuarioResponse" wsaw:Action="urn:inserirUsuarioResponse"/>
<wsdl:fault message="ns:UsuarioDAOSQLException" name="UsuarioDAOSQLException" wsaw:Action="urn:inserirUsuarioUsuarioDAOSQLException"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="UsuarioDAOSoap11Binding" type="ns:UsuarioDAOPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="efetuarLogin">
<soap:operation soapAction="urn:efetuarLogin" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="UsuarioDAOSQLException">
<soap:fault use="literal" name="UsuarioDAOSQLException"/>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="attUsuario">
<soap:operation soapAction="urn:attUsuario" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="UsuarioDAOSQLException">
<soap:fault use="literal" name="UsuarioDAOSQLException"/>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="excluirUsuario">
<soap:operation soapAction="urn:excluirUsuario" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="UsuarioDAOSQLException">
<soap:fault use="literal" name="UsuarioDAOSQLException"/>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="selUsuario">
<soap:operation soapAction="urn:selUsuario" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="UsuarioDAOSQLException">
<soap:fault use="literal" name="UsuarioDAOSQLException"/>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="inserirUsuario">
<soap:operation soapAction="urn:inserirUsuario" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="UsuarioDAOSQLException">
<soap:fault use="literal" name="UsuarioDAOSQLException"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="UsuarioDAOSoap12Binding" type="ns:UsuarioDAOPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="efetuarLogin">
<soap12:operation soapAction="urn:efetuarLogin" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
<wsdl:fault name="UsuarioDAOSQLException">
<soap12:fault use="literal" name="UsuarioDAOSQLException"/>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="attUsuario">
<soap12:operation soapAction="urn:attUsuario" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
<wsdl:fault name="UsuarioDAOSQLException">
<soap12:fault use="literal" name="UsuarioDAOSQLException"/>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="excluirUsuario">
<soap12:operation soapAction="urn:excluirUsuario" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
<wsdl:fault name="UsuarioDAOSQLException">
<soap12:fault use="literal" name="UsuarioDAOSQLException"/>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="selUsuario">
<soap12:operation soapAction="urn:selUsuario" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
<wsdl:fault name="UsuarioDAOSQLException">
<soap12:fault use="literal" name="UsuarioDAOSQLException"/>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="inserirUsuario">
<soap12:operation soapAction="urn:inserirUsuario" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
<wsdl:fault name="UsuarioDAOSQLException">
<soap12:fault use="literal" name="UsuarioDAOSQLException"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="UsuarioDAOHttpBinding" type="ns:UsuarioDAOPortType">
<http:binding verb="POST"/>
<wsdl:operation name="efetuarLogin">
<http:operation location="efetuarLogin"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="attUsuario">
<http:operation location="attUsuario"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="excluirUsuario">
<http:operation location="excluirUsuario"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="selUsuario">
<http:operation location="selUsuario"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="inserirUsuario">
<http:operation location="inserirUsuario"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="UsuarioDAO">
<wsdl:port name="UsuarioDAOHttpSoap11Endpoint" binding="ns:UsuarioDAOSoap11Binding">
<soap:address location="http://localhost:8009/ExemploWS/services/UsuarioDAO.UsuarioDAOHttpSoap11Endpoint/"/>
</wsdl:port>
<wsdl:port name="UsuarioDAOHttpSoap12Endpoint" binding="ns:UsuarioDAOSoap12Binding">
<soap12:address location="http://localhost:8009/ExemploWS/services/UsuarioDAO.UsuarioDAOHttpSoap12Endpoint/"/>
</wsdl:port>
<wsdl:port name="UsuarioDAOHttpEndpoint" binding="ns:UsuarioDAOHttpBinding">
<http:address location="http://localhost:8009/ExemploWS/services/UsuarioDAO.UsuarioDAOHttpEndpoint/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Javascript to call the post method

$.post('php/usuarioDAO.php',{usuario: $('#usuario').val(), senha: $('#senha').val()})
                .done( function(dados)
        {
            $('#resposta').html(dados);
        });

PHP code

<?php

extract($_POST);

$url = "http://localhost:8009/ExemploWS/services/UsuarioDAO?wsdl";

$param = new stdClass;
$param->usuario = $usuario;
$param->senha = $senha;

$soap = @new SoapClient($url, array('exceptions'=>true,'connection_timeout'=>1000));
try
{
    $resposta = $soap->efetuarLogin($param);
        echo "Usuario: ". $resposta->return->nome; //LINHA 17 QUE É CITADA NO ERRO

}catch(Exception $error)
{
    $resposta = $error->getMessage();
}

?>

Error message

Notice: Trying to get Property of non-object in C: xampp htdocs teste2 php usuarioDAO.php on line 17 Usuario:

I also tried with this code

 <?php
require_once 'lib/nusoap.php';
$client = new nusoap_client('http://localhost:8009/ExemploWS/services/UsuarioDAO?wsdl');

if($client->getError())
{
    echo "erro no construtor".$client->getError();
}
$object = array("login" => "abc","senha"=>"123");
$result = $client->call('efetuarLogin',array('efetuarLogin' => $object));

print_r ($result);

?>

but that’s the message

Array
(
[faultcode] => soapenv:Server
[faultstring] => namespace Mismatch require http://appvendas.sata.com.br found http://tempuri.org
[Detail] =>
)

  • Line 17 is which? could it be evidenced

  • I marked a comment in php code where line 17 is

  • If you give a print_r() in $resposta comes blank?

  • gave this message 'stdClass Object ( [Return] => )'

  • would also like to know how I can debug php code in netbeans, I downloaded this "php_xdebug-2.3.3-5.4-vc9-nts.dll" but do not know how to install it

  • vc can enable it in php.ini by removing the dot and comma from that line: ;zend_extension = "C:\xampp\php\ext\php_xdebug.dll" then restart the server, maybe this link help configure it.

Show 1 more comment

1 answer

1


I managed to solve using the following code

<?php
require_once 'lib/nusoap.php';
$client = new nusoap_client('http://localhost:8009/ExemploWS/services/UsuarioDAO?wsdl',true);

if($client->getError())
{
    echo "erro no construtor".$client->getError();
}
$object = array("login" => "abc","senha"=>"123");
$result = $client->call('efetuarLogin',array('parameters' => $object));
$obj = $result['return'];
//print_r($result);
echo $obj['nome'];

?>

what was missing was to put TRUE after the web service address, I used two array, because my object returned an array inside the other, so I only passed the array 'Return' to the variable obj

Browser other questions tagged

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