Create SOAP request with element attribute using Zend_Soap_Client and stdObject

孤街浪徒 提交于 2019-12-11 10:34:14

问题


I'm calling a service witch among many other parameters demands an entry like (Taken from soapUI):

  <v110:ReadWorkerRequest>
     <v111:Key v111:type="INITIALS">RKM</v111:Key>
  </v110:ReadWorkerRequest>

How do I get the Zend_Soap_Client to send the type-attribute in the Key element?

As this is just part of a rather big service, I've been creating classes to create the datastructure, like:

class Key {
  public $_ = 'RKM;
  public $type = 'INITIALS';
}

class Body {
  public $ReadWorkerRequest;

  public function __construct() {
    $this->ReadWorkerRequest = new Key();
  }
}

However, I do not even get to sending the request as PHP fails, telling me: "SOAP-ERROR: Encoding: object hasn't 'Key' property"

So my question is, how do I create an object structure, possibly with a subpart created as an Array which will honor this?

Or is the object structure correct, and I need to use classmap or SoapVar (I tried some combinations, but not with any success)

Happy holidays, for those of you who has them! :-)


回答1:


I have spent many hours myself trying to solve this problem but the best I could come up with was to use the XSD_ANYXML hack, eg:

$this->ReadWorkerRequest = new SoapVar( '<v111:Key v111:type="INITIALS">RKM</v111:Key>', XSD_ANYXML );

Its a pretty nasty hack though. Hopefully somebody else can provide a better solution.



来源:https://stackoverflow.com/questions/8577016/create-soap-request-with-element-attribute-using-zend-soap-client-and-stdobject

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!