Error with webservice SOAP using PHP

3

I'm trying to learn how to webservice using this tutorial: link

But my server is returning the following:

  

Error

     

Response of type text / xml: text / html

This is my client.php :

<?php
    require_once "lib/nusoap.php";
    $client = new nusoap_client("soma.wsdl", true);

    $error = $client->getError();
    if ($error) {
        echo "<h2>Constructor error</h2><pre>" . $error . "</pre>";
    }

    $result = $client->call("soma", array("a" => "1", "b" => "2"));

    if ($client->fault) {
        echo "<h2>Fault</h2><pre>";
        print_r($result);
        echo "</pre>";
    }
    else {
        $error = $client->getError();
        if ($error) {
            echo "<h2>Error</h2><pre>" . $error . "</pre>";
        }
        else {
            echo "<h2>Soma</h2><pre>";
            print_r($result);
            echo "</pre>";
        }
    }
?>

And this is my server.php :

<?php
    require_once "lib/nusoap.php";

    function soma($a, $b) {
        return $a + $b;
    }
    $server = new soap_server();
    $server->configureWSDL("resultado", "urn:resultado");

    $server->register("soma",           // nome da função
    array("category" => "xsd:int"),     // tipo de entrada (inteiro, string...)
    array("return" => "xsd:int"),       // tipo de saída
    "urn:resultado",                    // define o namespace
    "urn:resultado#soma",               // define a ação do SOAP
    "rpc",                              // define o tipo da chamada
    "encoded",                          // define o valor para o atributo 'use'
    "Retorna a soma de dois números");  // documentação do que a função faz

    $server->service($HTTP_RAW_POST_DATA);
?>

And finally, this is my soma.wsdl :

<definitions 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:tns="urn:resultado" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:resultado">
    <types>
        <xsd:schema targetNamespace="urn:resultado">
            <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
            <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
        </xsd:schema>
    </types>
    <message name="somaRequest">
        <part name="category" type="xsd:int"/>
    </message>
    <message name="somaResponse">
        <part name="return" type="xsd:int"/>
    </message>
    <portType name="resultadoPortType">
        <operation name="soma">
            <documentation>Retorna a soma de dois números</documentation>
            <input message="tns:somaRequest"/>
            <output message="tns:somaResponse"/>
        </operation>
    </portType>
    <binding name="resultadoBinding" type="tns:resultadoPortType">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="soma">
            <soap:operation soapAction="urn:resultado#soma" style="rpc"/>
            <input>
                <soap:body use="encoded" namespace="urn:resultado" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </input>
            <output>
                <soap:body use="encoded" namespace="urn:resultado" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </output>
        </operation>
    </binding>
    <service name="resultado">
        <port name="resultadoPort" binding="tns:resultadoBinding">
            <soap:address location="http://renanlazarotto.com/server/server.php"/>
        </port>
    </service>
</definitions>

I can not understand where the error is. What should I do for the error to go away? If I put the webservice address in place of soma.wsdl, this is the result:

  

Sum

     

3

What is expected of the webservice.

    
asked by anonymous 06.09.2014 / 05:44

1 answer

1

The expected response type is an XML and it is receiving HTML.

  

Response of type text / xml: text / html

You can consume your service using the REST Client for testing, and if so force the php header to return you an XML.

To add a Header make sure nothing is going on in the header before adding the command, place it after you start

08.09.2014 / 15:51