我是否在使用PHP SOAP_CLIENT做错了什么?

时间:2013-03-11 17:52:58

标签: php web-services soap wsdl

我对SOAP有一个非常基本的了解,对我来说,我认为SOAP是两个不同语言的翻译者,他们都会说不同的语言,试图相互沟通。我试图使用PHP SOAP CLIENT从Web服务调用方法,但我无法使其工作,下面是Web服务服务器生成的WSDL:

<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://server.webservice.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="serviceServerService" targetNamespace="http://server.webservice.com/">
<wsdl:types>
<schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://server.webservice.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://server.webservice.com/" schemaLocation="http://127.0.0.1:8080/WebbServiceServer/services/serviceServerPort?xsd=serviceserver_schema1.xsd"/>
</schema>
</wsdl:types>
<wsdl:message name="userInputResponse">
<wsdl:part element="tns:userInputResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="userInput">
<wsdl:part element="tns:userInput" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="serviceInterface">
<wsdl:operation name="userInput">
<wsdl:input message="tns:userInput" name="userInput"></wsdl:input>
<wsdl:output message="tns:userInputResponse" name="userInputResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="serviceServerServiceSoapBinding" type="tns:serviceInterface">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="userInput">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="userInput">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="userInputResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="serviceServerService">
<wsdl:port binding="tns:serviceServerServiceSoapBinding" name="serviceServerPort">
<soap:address location="http://127.0.0.1:8080/WebbServiceServer/services/serviceServerPort"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

我从上面的WSDL中理解的是,我试图调用的方法是userInput,它接受​​一个字符串参数,userInputResponse是来自服务器的响应,它将输出任何内容返回userInput方法。下面是我尝试运行的PHP CLIENT的代码:

<?php
$a = array("userInput" => "This is the input");
$client = new SoapClient("http://127.0.0.1:8080/WebbServiceServer/services/serviceServerPort?wsdl", array('exceptions' => 0));

$result = $client->userInput($a);
//$functions = $client->__getFunctions();
//var_dump($client->__soapCall("userInput", $a));
//var_dump($functions);

print_r($result->userInputResponse);

if (is_soap_fault($result)) {
    trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
}
?>

我尝试运行PHP CLIENT,但不幸的是它打印错误:

Notice: Undefined property: stdClass::$userInputResponse in C:\xampp\htdocs\PHP_SOAP_CLIENT\index.php on line 14

要测试客户端是否调用了方法userInput,如果返回了某些内容,我会使用var_dump()

var_dump($result);

,输出结果为:

object(stdClass)#2 (1) { ["return"]=> string(56) "Hi! this is from JAVA Web services, your input was: null" }

很好,它确实返回了一些东西,但方法没有得到我传递的字符串。我希望有人可以识别并解释我的代码的缺陷,非常感谢任何评论和答案,谢谢。

1 个答案:

答案 0 :(得分:0)

您尝试访问返回值是错误的。您可以在userInputResponse中看到,没有属性var_dump()。实际上,返回值存储在属性return中。

我无法真正看到这是在WSDL中定义的,但我认为它不完整。还有一个可能加载的XSD的引用,可以包含更多定义。

相关问题