gpt4 book ai didi

php - 从使用 php 构建的 Web 服务中获取空响应

转载 作者:搜寻专家 更新时间:2023-10-31 20:46:48 25 4
gpt4 key购买 nike

我想用 php 和 zend 框架创建一个网络服务。服务器端代码如下:

csiService.php:

<?php
require_once 'Zend/Loader.php';
require_once 'CSI.php';
$WSDL_URI="http://csi.chemicalseeker.com/csiService.php?WSDL";
if(isset($_GET["WSDL"]))
{
Zend_Loader::loadClass('Zend_Soap_AutoDiscover');
Zend_Loader::loadClass('Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence');
$autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence');
$autodiscover->setBindingStyle(array('style' => 'document'));
$autodiscover->setOperationBodyStyle(array('use' => 'literal'));
$autodiscover->setClass('CSI');
$autodiscover->handle();
}
else
{
Zend_Loader::loadClass('Zend_Soap_Server');
$server = new Zend_Soap_Server($WSDL_URI);
$server->setClass('CSI');
$server->handle();
}
?>

其中包括 CSI.php:

<?php
class CSI {
/**
* @return string
*/
function helloWorld()
{
return("Hello");
}
}
?>

*我编辑了主机文件,以便将域“csi.chemicalseeker.com”绑定(bind)到 127.0.0.1当我在浏览器中访问“http://csi.chemicalseeker.com/csiService.php?WSDL”时,WSDL 运行良好:

<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://csi.chemicalseeker.com/csiService.php" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="CSI"
targetNamespace="http://csi.chemicalseeker.com/csiService.php">
<types>
<xsd:schema targetNamespace="http://csi.chemicalseeker.com/csiService.php">
<xsd:element name="helloWorld">
<xsd:complexType />
</xsd:element>
<xsd:element name="helloWorldResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="helloWorldResult" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</types>
<portType name="CSIPort">
<operation name="helloWorld">
<documentation>@return string</documentation>
<input message="tns:helloWorldIn" />
<output message="tns:helloWorldOut" />
</operation>
</portType>
<binding name="CSIBinding" type="tns:CSIPort">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="helloWorld">
<soap:operation
soapAction="http://csi.chemicalseeker.com/csiService.php#helloWorld" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="CSIService">
<port name="CSIPort" binding="tns:CSIBinding">
<soap:address location="http://csi.chemicalseeker.com/csiService.php" />
</port>
</service>
<message name="helloWorldIn">
<part name="parameters" element="tns:helloWorld" />
</message>
<message name="helloWorldOut">
<part name="parameters" element="tns:helloWorldResponse" />
</message>
</definitions>

我还编写了一个名为 CSIClient.php 的 php 客户端文件,并从浏览器访问它:

CSIClient.php

<?php
require_once 'Zend/Loader.php';
require_once 'CSI.php';
Zend_Loader::loadClass('Zend_Soap_Client');
$WSDL_URI="http://csi.chemicalseeker.com/csiService.php?WSDL";

$client = new Zend_Soap_Client($WSDL_URI);
echo('<pre>');
var_dump($client->helloWorld());
echo('</pre>');
?>

结果应该是一个内容为“Hello”的字符串,但它显示的是一个空的 stdObject:

object(stdClass)#3 (0) {
}

我可以通过“$client->getFunctions()”和“$client->getTypes()”获取函数列表和类型列表,这意味着“CSI”类已经成功连接到网络服务。但无法正确返回结果。

我还尝试了其他方法来调用网络服务。我用Flash Builder调用helloWorld()函数,服务器响应如下:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://csi.chemicalseeker.com/csiService.php">
<SOAP-ENV:Body>
<ns1:helloWorldResponse/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

正如我们所见,预期结果“Hello”也不包含在 SOAP 信封中。我是否遗漏了一些重要的东西或在我的代码中犯了一些错误?如果你有线索,请帮助我。谢谢!

最佳答案

我也在为此苦苦挣扎,但我通过切换到非 WSDL 模式设法解决了您遇到的上述问题。

无论我尝试什么,我总是收到与尝试从我自己的自动发现生成的 WSDL 加载 WSDL 时相同的空响应。 (感觉可能存在一些递归问题,但我现在看不到)

无论如何,切换到非 WSDL 模式给了我正确的响应。

尝试按如下方式创建您的服务器:

$server = new Zend_Soap_Server(null, array('uri' => $WSDL_URI));

关于php - 从使用 php 构建的 Web 服务中获取空响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12269365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com