私は最初のSOAPサーバーを作成しようとしていますが、SOAPクライアントを少し使用しました。単一の文字列を送信してみたところ、これは問題なく機能しました。しかし、サーバーに複数のパラメーターを送信しようとすると、スタックが解除されます。これに取り組むためのより良い方法はありますか?
サーバ:
<?php
if(!extension_loaded("soap")){
dl("php_soap.dll");
}
ini_set("soap.wsdl_cache_enabled","0");
function getCatalogEntry($array){
$conn = mysqli_connect($host,$user,$password,$db) or die(mysqli_error($conn));
$sql = "SELECT '" . $array[0]. "' FROM soap WHERE id = '".$array[1]."'";
$result = $conn->query($sql) or die(mysqli_error($conn));
$row = mysqli_fetch_array($result);
return var_dump($array).$array[0];//$sql.$row[$field];
}
$server = new SoapServer("test.wsdl");
$server->AddFunction("getCatalogEntry");
$server->handle();
?>
クライアント:
<?php
try{
$sClient = new SoapClient('server.php?wsdl');
$params = array(
"field" => "field2",
"id" => "id");
$response = $sClient->getCatalogEntry($params);
var_dump($response);
} catch(SoapFault $e){
var_dump($e);
}
?>
WSDL:
<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='Catalog'
targetNamespace='http://example.org/catalog'
xmlns:tns=' http://example.org/catalog '
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
xmlns='http://schemas.xmlsoap.org/wsdl/'>
<xsd:complexType name="KeyValueData">
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="1" name="id" type="string"/>
<xsd:element minOccurs="1" maxOccurs="1" name="field" type="string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ArrayOfKeyValueData">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded"
name="keyval" type="tns:KeyValueData"/>
</xsd:sequence>
</xsd:complexType>
<message name='getCatalogRequest'>
<part name='catalogId' type='ArrayOfKeyValueData'/>
</message>
<message name='getCatalogResponse'>
<part name='Result' type='xsd:string'/>
</message>
<portType name='CatalogPortType'>
<operation name='getCatalogEntry'>
<input message='tns:getCatalogRequest'/>
<output message='tns:getCatalogResponse'/>
</operation>
</portType>
<binding name='CatalogBinding' type='tns:CatalogPortType'>
<soap:binding style='rpc'
transport='http://schemas.xmlsoap.org/soap/http'
/>
<operation name='getCatalogEntry'>
<soap:operation soapAction='urn:localhost-catalog#
getCatalogEntry'/>
<input>
<soap:body use='encoded' namespace=
'urn:localhost-catalog'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</input>
<output>
<soap:body use='encoded' namespace=
'urn:localhost-catalog'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' />
</output>
</operation>
</binding>
<service name='CatalogService'>
<port name='CatalogPort' binding=
'CatalogBinding'>
<soap:address location='server.php'/>
</port>
</service>
</definitions>