Ошибка веб-службы SOAP с использованием PHP


Я пытаюсь научиться делать webservice, используя этот учебник: http://www.sitepoint.com/web-services-with-php-and-soap-2/

Но мой server возвращает следующим образом:

Error

Response not of type text/xml: text/html

это мой 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>";
        }
    }
?>

И это мой 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);
?>

И, наконец, это мой сумма.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>

Не могу понять, где ошибка. Что я должен сделать, чтобы ошибка исчезнет? Если я помещаю адрес webservice на месте сумма.wsdl, это результат:

Sum

3

, ожидается webservice.

Author: Renan Lazarotto, 2014-09-06

1 answers

Типа ожидаемого ответа-это XML, и он получает HTML.

Response not of type text/xml: text/html

И Вы можете потреблять их услуги, используя REST Client для тестирования, и, если необходимо force заголовок php тебя возвращать XML.

, Чтобы добавить Заголовок, убедитесь, что вы не собираетесь ничего в заголовок, прежде чем добавлять строки, поставьте после запуска

Ex:

<?php header('Content-Type:text/xml');
//Aqui continua o código.
?>
 1
Author: Hiago Souza, 2014-09-08 16:13:56