PHP-SOAP SoapFault异常:[Client]看起来没有XML文档


PHP-SOAP SoapFault exception: [Client] looks like we got no XML document

我目前正在本地主机上测试和使用Web服务。我在程序的客户端调用中得到了"SoapFault异常:[Client]看起来我们没有XML文档",我似乎找不到原因。

我已经将编码更改为没有BOM的UTF8(正如在其他问题上所建议的那样),但仍然没有。我认为这可能是因为我在wsdl规范中使用了complextype。

以下是wsdl中我认为重要的部分:

<types>
<xsd:schema targetNamesace="urn:consulta">
    <xsd:simpleType name="codigo">
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="1"/>
            <xsd:maxLength value="255"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="designacao">
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="1"/>
            <xsd:maxLength value="255"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="unidades">
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="1"/>
            <xsd:maxLength value="255"/>
        </xsd:restriction>
    </xsd:simpleType>   
    <xsd:simpleType name="quantidade">
        <xsd:restriction base="xsd:decimal">
            <xsd:minLength value="2"/>
            <xsd:maxLength value="18"/>
        </xsd:restriction>
    </xsd:simpleType>   
    <xsd:simpleType name="referencia">
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="1"/>
            <xsd:maxLength value="255"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:complexType name="MapaQuantidades">
        <xsd:sequence>
            <xsd:element name="codigo" type="tns:codigo"/>
            <xsd:element name="designacao" type="tns:designacao"/>
            <xsd:element name="unidades" type="tns:unidades"/>
            <xsd:element name="quantidade" type="tns:quantidade"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>
</types>

我在客户端上使用的代码是:

    $wsdl= "....";
$soap_options = array(
    'trace'       => 1,     // traces let us look at the actual SOAP messages later
    'exceptions'  => 1 );
$cliente = new SoapClient($wsdl, $soap_options);
$mapaQtds = new StdClass();
$mapaQtds->MapaQuantidades = new StdClass();
$mapaQtds->MapaQuantidades->codigo = 'Codigo WS';
$mapaQtds->MapaQuantidades->designacao = 'Designacao WS';
$mapaQtds->MapaQuantidades->unidades = 'Unidades WS';
$mapaQtds->MapaQuantidades->quantidade = 20;
$soapstruct = new SoapVar($mapaQtds, SOAP_ENC_OBJECT);
$referencia = "Referencia WS";
$designacao = "Designacao Principal";
try{
    $valor = $cliente->create_consulta( $referencia, $designacao, $soapstruct);
    //echo "Resultado = " . $valor;
    echo "REQUEST:'n" . $client->__getLastRequestHeaders() . "'n";
}catch(SoapFault $e){
    var_dump($e);
}

目前,服务器上的函数只返回true。。。但程序似乎甚至没有到达服务器。它在$client->create_consulta中"死亡"。你知道为什么会发生这种事吗?

完整错误为:

Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document     in C:'xampp'htdocs'Integration'Agregation'WSConsultaClient.php:30 Stack trace: #0 C:'xampp'htdocs'Integration'Agregation'WSConsultaClient.php(30): SoapClient->__call('create_consulta', Array) #1 C:'xampp'htdocs'Integration'Agregation'WSConsultaClient.php(30): SoapClient->create_consulta('Referencia WS', 'Designacao Prin...', Object(SoapVar)) #2 {main} thrown in C:'xampp'htdocs'Integration'Agregation'WSConsultaClient.php on line 30

Thx,CR

检查你的服务器代码,我有同样的问题,我解决了它,删除了所有的echo,?>,和html代码,您的server.php必须是一个空白页面