2009-11-04 100 views
1

沒有得到數據以下是我的web服務調用從數據類2種方法(registerCustomer和的getCountries):從web服務

<!-- a string array req param, used as a return for the getAvailable cars method --> 
<message name="response"> 
<part name="resParam" type="tns:strArray"/> 
</message> 

<!-- just a string message --> 
<message name="request"> 
    <part name="reqParam" type="xsd:string"/> 
</message> 

<!-- Methods published, together with there inputs and outputs --> 
<portType name="testPortType"> 
<!-- Method 0. Takes nothing returns a string array --> 
    <operation name="getCountries"> 
    <output message="tns:response"/> 
</operation> 
<!-- Method 1. Takes a string param and returns nothing --> 
<operation name="registerCustomer"> 
    <input message="tns:request"/> 
</operation> 
<!-- Method 2. Takes a string param and returns nothing --> 
<operation name=""> 
    <input message="tns:request"/> 
</operation> 
</portType> 

<!-- define the transport and protocol --> 
<binding name="testBinding" type="tns:testPortType"> 
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> 
    <operation name="getCountries"> 
    <soap:operation soapAction=""/> 
<output> 
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:mymyInputNamespace"/> 
    </output> 

</operation> 
<operation name="registerCustomer"> 
    <soap:operation soapAction=""/> 
    <input> 
    <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:mymyInputNamespace"/> 
</input> 
</operation> 
</binding> 

<!-- who implements these services ? --> 
    <service name="testService"> 
    <port name="testPort" binding="tns:testBinding"> 
     <soap:address location="http://localhost/dataobjects/dataclass.php"/> 

從PHP頁面他們不訪問,這是給我下面的錯誤:

Fatal error: Call to undefined method SoapServer::getCountries() in C:\Program Files\xampplite\htdocs\testingpage.php on $dataset = $dataobj->getCountries();

$dataobj = new SoapServer("http://localhost/dataobjects/myWebservice.wsdl", array('soap_version' => SOAP_1_2,'trace' => 1)); 
$dataset = $dataobj->getCountries(); 
    echo("<h2>Available Countries (".count($dataset)."):</h2><br />"); 

    foreach($dataset as $c) { 
    echo($c.", "); 

回答

0

通話 web服務,嘗試這樣的事情:

try{ 
    $service = "http://example.org/myWebService.wsdl"; 
    $client = new SoapClient($service, array('location' =>"http://example.org/myWebService")); 
    $parameter1 = new myWebServiceParameter(); 
    $result = $client->myWebServiceFunction($parameter1); 
} catch (Exception $e) { 
    // handle errors 
} 

您必須提供Web服務端點的URL不是您的WSDL。 myWebServiceParameter必須是任何具有相同名稱的WSDL消息屬性的成員變量的類。 而myWebServiceFunction是Web服務方法的名稱。

爲Web服務則可能是:

try{ 
    $service = "http://localhost/dataobjects/myWebservice.wsdl"; 
    $client = new SoapClient($service, array('location' =>"http://localhost/dataobjects/myWebservice")); 
    $result = $client->getCountries(); 
} catch (Exception $e) { 
    // handle errors 
} 
+0

嘗試過了,你告訴我: 嘗試 { \t $服務= 「HTTP://localhost/dataobjects/myWebservice.wsdl」; \t $ dataobj = new SoapClient($ service,array('location'=>「http:// localhost/dataobjects/myWebservice」)); \t $ dataset = $ dataobj-> getCountries(); } catch(Exception $ e){echo $ e; } 現在它給了我另外一個錯誤: SoapFault異常:C:\ Program Files \ xampplite \ htdocs \ testingpage.php中的SOAP不支持[客戶端] DTD:13堆棧跟蹤:#0 [內部函數]:SoapClient - > __ call('getCountries',Array)#1 C:\ Program Files \ xampplite \ htdocs \ testingpage.php(13):SoapClient-> getCountries()#2 {main} – IanCian 2009-11-04 15:56:29

+0

您不能使用DTD來驗證您的XML消息,而是使用XML模式(或者什麼也不使用)。 – 2009-11-04 21:10:37