我目前正在我的本地主机上测试和使用 web 服务。我在程序的客户端调用中收到“SoapFault 异常:[Client] 看起来我们没有 XML 文档”,但我似乎找不到原因。
我已经将编码更改为没有 BOM 的 UTF8(正如其他问题所建议的那样),但仍然没有。我认为这可能是因为我的 wsdl 规范中的复杂类型。
这是我认为重要的 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
提前谢谢,CR