I’m writing a SOAP API in PHP and I’m stuck. I’m trying to return a Dictionary object with this format:
Key: #
Value:
Id: #
Title: some title
Text: blahI’ve been looking through the WSDL and XSD files of another site’s SOAP API service and I’ve figured out how to write a Dictionary object into them, now I’m stuck at the PHP part. My Dictionary is set up in the WSDL / XSD to have an integer as the key and a Comment object as the value, so it should be an array of int key / Comment value pairs…but I just can’t figure out how to do it in PHP. Here is the structure I’ve got in my XSD file:
Can someone help me out with this, just help me wrap my head around how this should work in PHP. Thanks!
…………………………………..
Well, since I had nothing better to do, I kept tinkering with it and figured it out. I had most of the right elements, just in the wrong order.
My WSDL stayed the same, I didn’t have to change anything there. In my first XSD, I changed my output element to this:
class GetDictionaryResponse {
var $GetDictionaryResult;
function GetDictionaryResponse() {
$this->GetDictionaryResult = new GetDictionaryResult();
}
}
class GetDictionaryResult {
var $status;
var $Data;
function GetDictionaryResult() {
$this->status = (string)”Ok”;
}
function AddItem($k, $v) {
$d = new ArrayOfKeyValueOfintComment($k, $v);
$this->Data[] = $d;
}
}
class ArrayOfKeyValueOfintComment {
var $Key, $Value;
function ArrayOfKeyValueOfintComment($k, $v) {
$this->Key = $k;
$this->Value = $v;
}
}
function GetDictionary() {
$ret = new GetDictionaryResponse();
for($i = 0; $i < 3; $i++) {
$c = new Comment(array([comment elements]));
$ret->GetDictionaryResult->AddItem($i, $c);
}
return $ret;
}Hopefully it doesn’t look too confusing. Essentially the return looks like this:
GetDictionaryResponse->
GetDictionaryResult->
string status;
Dictionary
I can consume it in .Net and get a valid Dictionary from it like this:
DictionaryResponse r = client.GetDictionary(); Comment c = r.Data[0];
Hopefully I’ve helped some future readers out!