Error with SOAP webservice using PHP

Question:

I'm trying to learn how to make a webservice using this tutorial: http://www.sitepoint.com/web-services-with-php-and-soap-2/

But my server is returning the following:

error

Response not 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 sum.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't understand where the error is. What should I do to make the error go away? If I put the webservice address in place of soma.wsdl, this is the result:

Sum

3

What is expected from the webservice.

Answer:

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

Response not of type text/xml: text/html

You can consume your service using the REST Client to do tests, and if that's the case, 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, put it after starting the <?php

Ex:

<?php header('Content-Type:text/xml');
//Aqui continua o código.
?>
Scroll to Top