Php肥皂服务evenlope 元素

问题描述:

我想建立一个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

我不认为你可以,我认为这是写入SOAP的核心,所以这是你的客户必须解决的问题。如果他们已经获得PingResponse的内容,我不会看到他们更难以更深入地回答1树。