2011-11-15 12 views
1

私はZend Soap Serverを持っていて、setUser()操作を作成しました。この操作では、最終的に要求されたデータが使用され、新しいUserオブジェクトが挿入されます。したがって、オブジェクトの値を持つ配列を要求したいと思います。PHP SOAPリクエスト:キーが必要な配列

例:

私は、値のみの数字キーを取得し、私のPHPコードで配列をダンプすると、次のリクエストは基本的に配列

<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:soap="..."> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <soap:setUser soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
     <setArray xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
      <item xsi:type="xsd:string">John</item> 
      <item xsi:type="xsd:string">Doe</item> 
     </setArray> 
     </soap:setUser> 
    </soapenv:Body> 
</soapenv:Envelope> 

のために働く

$request = array("firstname" => "John", "lastname" => "Doe"); 
setUser($request) { ... } 

[0] => John 
[1] => Doe 

キーを指定する方法はありますか?私はすでに試した:

<element name="firstname" xsi:type="xsd:string">John</element> 

を私が達成したい:

[firstname] => John 
[lastname] => Doe 

感謝を。

答えて

0

Zend_SOAP_Serverの正確な解決策がわかりませんが、配列ではなくHashMap型を使用したいと思います。配列のキーが破棄されるか、要素名として使用されます。どちらもPHPの「配列」型の無効な表現です)

このような表現で終わりたいです:

<hash xmlns:ns2="http://xml.apache.org/xml-soap" xsi:type="ns2:Map"> 
<item> 
    <key xsi:type="xsd:string">firstname</key> 
    <value xsi:type="xsd:string">John</value> 
</item> 
<item> 
    <key xsi:type="xsd:string">lastname</key> 
    <value xsi:type="xsd:string">Doe</value> 
</item> 
</hash> 

ほとんどのSOAPサーバーは、クライアントの実装がデフォルトになっていなくても、この罰金を解読しているようです。

はどちらかそれは、またはあなたがより多くのこのようなカスタム文書スキーマを定義する必要があります。

<userStruct xsi:type="myNamespace:userStruct"> 
<firstname xsi:type="xsd:string">John</value></firstname> 
<lastname>Doe</lastname> 
</userStruct> 

は個人的に、私はそれを解決するが、YMMVよりSOAPは多くの問題を作成し、発見する傾向があります。

function toObject($array) { 
    foreach ($array as $key=>$value) 
     if (is_array($value)) 
      $array[$key] = toObject($value); 
    return (object)$array; 
} 

次にあなたがそのオブジェクトを返すことができますし、次のようにサーバーの応答を処理しながら、それはXMLにエクスポートします:

<firstname xsi:type="xsd:string">lastname</firstname> 
    <lastname xsi:type="xsd:string">Doe</lastname> 

:)

0

あなたはこのように、たとえば配列からstdClass()を作ることができます私はZend_Soap_Server()を使用しています。

関連する問題