2013-03-11 43 views
0

我有一個關於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" } 

罰款它確實返回的東西,但方法沒有得到我通過的字符串。我希望有人能夠識別和解釋我的代碼的缺陷,非常感謝任何意見和答案。

+0

它看起來像你試圖使用屬性userInputResponse,當它沒有定義。在使用類時,它就像變量等的DOM樹。所以它看起來可能是'root-> subclass-> prop'。也許這會清理一些東西。 – Mic1780 2013-03-11 18:02:22

+0

大聲笑,我現在明白了我沒有看到包含正在調用根的參數的正確名稱的模式,「 ' – Rojee 2013-03-11 19:22:41

回答

0

您嘗試訪問返回值是錯誤的。沒有財產userInputResponse,您可以在您的var_dump()中看到。實際上,返回值是存儲在屬性return中。

我看不出這是在WSDL中定義的,但我認爲它是不完整的。有一個對另一個XSD的引用,它可能也被加載,並且可以包含更多的定義。

+0

謝謝你,那正是我犯的錯誤不要檢查位於http://127.0.0.1:8080/WebbServiceServer/services/serviceServerPort?xsd = serviceserver_schema1.xsd'中的其他XSD,其中包含其他定義。 – Rojee 2013-03-12 17:05:04