开发者

PHP Soap - How to remove xsi:type= from XML tag

I'm sending a SOAP request that looks like:

<SOAP-ENV:Body>
  <api:GetOrder xsi:type="SOAP-ENC:Struct">
    <api_orderId xsi:type="xsd:int">1234</api_orderId>
  </api:GetOrder>
</SOAP-ENV:Body>

But needs to look like this (SoapUI generated):

<soapenv:Body>
  <api:GetOrder>
    <api:orderId>1234</api:orderId>
  </api:GetOrder>
</soapenv:Body>

My PHP Code:

$client = $this->getConnection();
$soap_options = array('soapaction' => $config->getValue('soapaction_url') . 'GetOrder');
$obj = new stdClass();
$obj->api_orderId = 59698;

$results = $client->__soapCall('GetOrder', array(new SoapParam($obj, "api:GetOrder")), $soap_options);

2 questions really:

1) How can I remove the "xsi:type" from the request? (If I add xsi:type in to my SoapUI 开发者_运维知识库request, I get back a "400 Bad Request"

2) Instead of "api_orderId" I need to send "api:orderId", but I can't name an object with a colon, so do I have to pass the name and value as an array somehow?

Appreciate any help, thank you.

EDIT:

I wasn't able to figure out any other way to send these requests and I essentially ended up doing as Mr.K suggested below. I wrote a custom class to extend SoapClient. Then overrode the __doRequest method to send my own custom SOAP request.

The only downside is that SOAP no longer returns me an array of objects, so I also had to parse the XML of the SOAP response. Also I suspect that the performance of doing it this way is a bit slower, but I didn't notice it.


Try with Simple XML parsing, and create the new request as you like.

Read the tag values from Original request, assign those values to a new XML object using parsing. You can create string of XML message and load it as an XML object in PHP.

Just like get it from there, put it inside this..and Send!..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜