2010-11-18 179 views
1

我想建立一個Web服務的第三方誰將連接到它作爲一個客戶端的規範,該服務必須用PHP編寫,但我是一個總PHP的PHP n00b如此掙扎一點。基本上我的回覆被封裝在一個元素中,但客戶端並沒有接受我的迴應,因此,這裏是一個例子。Php肥皂服務evenlope <return>元素

service.php

<?php 


class MyService { 

    public function Ping() { 
     return date('d/m/Y H:i:s'); 
    } 

} 


$server = new SoapServer(null, array('soap_version' => SOAP_1_2, 'encoding' => 'UTF-8', 'uri' => 'http://tempuri.org/')); 
$server->setClass("MyService"); 
$server->handle(); 

?> 

請求

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns:tem="http://tempuri.org/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <tem:Ping /> 
    </soapenv:Body> 
</soapenv:Envelope> 

響應

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> 
    <SOAP-ENV:Body> 
     <ns1:PingResponse> 
     <return xsi:type="xsd:string">18/11/2010 18:51:02</return> 
     </ns1:PingResponse> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

什麼客戶期待是PingResponse只包含日期,但沒有外繞纏。我怎樣才能讓PHP SoapClient執行此操作?

E.g.

<ns1:PingResponse>18/11/2010 18:51:02</ns1:PingResponse> 
+0

你有沒有試過用這種格式的純XML回覆? – stillstanding 2010-11-18 19:52:59

回答

0

我不認爲你可以,我認爲這是寫入SOAP的核心,所以這是你的客戶必須解決的問題。如果他們已經獲得PingResponse的內容,我不會看到他們更難以更深入地回答1樹。