我正在構建一個使用php核心SOAP類的Web服務,並且需要返回一個枚舉類型的變量。這是在WSDL類型定義:如何在PHP SOAP服務器中返回枚舉類型
<xsd:simpleType name="ErrorCodeEnum">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="OK"/>
<xsd:enumeration value="INTERNAL_ERROR"/>
<xsd:enumeration value="TOO_MANY_REQUESTS"/>
</xsd:restriction>
</xsd:simpleType>
server.php:
<?php
class testclass {
public function testfunc($param) {
$resp = new testResp();
$resp->errorCode = 'OK'; #SoapServer returns xsd:string type.
return $resp;
}
}
class testReq {}
class testResp {
public $errorCode;
}
$class_map = array('testReq' => 'testReq', 'testResp' => 'testResp');
$server = new SoapServer (null, array('uri' => 'http://test-uri/', 'classmap' => $class_map));
$server->setClass ("testclass");
$server->handle();
?>
答:
<ns1:testResponse>
<return xsi:type="SOAP-ENC:Struct">
<errorCode xsi:type="xsd:string">OK</errorCode>
</return>
</ns1:testResponse>
我該怎麼做才能返回類型ErrorCodeEnum
,而不是string
?
謝謝,但它是不一樣的問題。由於我正在建立一個服務器,而不是客戶端,我必須返回正確的類型。 – 2011-03-24 23:01:15