我有一個關於SOAP的基本知識,對於我來說,我認爲SOAP是兩個不同語言的翻譯人員,他們都說不同的語言,試圖互相溝通。我試圖使用PHP SOAP客戶端調用從Web服務的方法,但我不能得到它的工作,下面是由Web服務的服務器生成的WSDL:我的PHP SOAP_CLIENT有問題嗎?
<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客戶端,我試圖運行代碼:
<?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客戶端遺憾的是它打印錯誤:
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" }
罰款它確實返回的東西,但方法沒有得到我通過的字符串。我希望有人能夠識別和解釋我的代碼的缺陷,非常感謝任何意見和答案。
它看起來像你試圖使用屬性userInputResponse,當它沒有定義。在使用類時,它就像變量等的DOM樹。所以它看起來可能是'root-> subclass-> prop'。也許這會清理一些東西。 – Mic1780 2013-03-11 18:02:22
大聲笑,我現在明白了我沒有看到包含正在調用根的參數的正確名稱的模式,「 XS:序列> XS:的complexType> xs:sequence> xs:complexType>' –
Rojee
2013-03-11 19:22:41