PHP and Soap Client - Multi-Level Array as Argument

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 3935 Views - Last Post: 31 May 2012 - 01:59 PM Rate Topic: -----

#1 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

PHP and Soap Client - Multi-Level Array as Argument

Posted 28 May 2012 - 12:44 PM

I have been stumped for days, has any body had an issue with this?

I am sending requested with SOAP to a WSDL on a local server

I have gotten alot of the calls to work, but nothing with multidimensional arrays.. Mainly in arguments that require a list of ID's.

So this is where I set the arguments
$trx = $client->GetPaymentByTransactionId(array('XmlIds'=>array('Id'=>'61080')));


Here is the Soap's _lastRequest
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.harms-software.com/Millennium.SDK"><SOAP-ENV:Header><ns1:MillenniumInfo><ns1:MillenniumGuid>xxx-xxx-xxx-xxx</ns1:MillenniumGuid></ns1:MillenniumInfo><ns1:SessionInfo><ns1:SessionId>b83e2b51-315e-41e3-996e-1cf5f7f91bad</ns1:SessionId></ns1:SessionInfo></SOAP-ENV:Header><SOAP-ENV:Body><ns1:GetPaymentByTransactionId><ns1:XmlIds>Array</ns1:XmlIds></ns1:GetPaymentByTransactionId></SOAP-ENV:Body></SOAP-ENV:Envelope> 


Here is the WSDL Server Response
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ApplicationException: Invalid XML Ids List.
   at Harms_.e.a(String , String )
   at Harms_.s.b(String )
   at Millennium.SDK.MillenniumSDK.GetPaymentByTransactionId(String XmlIds)


Here is the documentation for this call
GetPaymentByTransactionId() - Millennium Harms

Any thoughts?
I have tried NuSoap but have had no success with that either

Is This A Good Question/Topic? 0
  • +

Replies To: PHP and Soap Client - Multi-Level Array as Argument

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2891
  • View blog
  • Posts: 10,025
  • Joined: 08-August 08

Re: PHP and Soap Client - Multi-Level Array as Argument

Posted 28 May 2012 - 12:53 PM

This doesn't look right:
<ns1:XmlIds>Array</ns1:XmlIds>

What happens if you use this?
$trx = $client->GetPaymentByTransactionId('61080');

Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,435
  • Joined: 23-August 08

Re: PHP and Soap Client - Multi-Level Array as Argument

Posted 28 May 2012 - 12:57 PM

WTF #1: SOAP.
WTF #2: Requiring a god-damn XML string as an argument to a SOAP call. That is ALL KINDS of FUCKED UP.

This is what is required as an argument...NOT an array:

http://update.harms-..._Definition.htm

Quote

Many of the Millennium SDK methods available require a list of Ids of the desired records to be returned. This list of Ids is to be passed as a well formatted XML string. The field name that contains the Ids must be named Id while the list name does not matter.

These lists of Ids should be formatted using the following XML IdList structure:

<[list name]>
<Ids>
<Id>
1
</Id>
</Ids>
<Ids>
<Id>
2
</Id>
</Ids>
</[list name]>


Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,435
  • Joined: 23-August 08

Re: PHP and Soap Client - Multi-Level Array as Argument

Posted 28 May 2012 - 01:25 PM

Something like this might work:

<?php

$xmlW = new XMLWriter();
$xmlW->openMemory();

$xmlW->startElement('MyIdList');
$xmlW->startElement('Ids');
for($i = 1; $i <= 5; ++$i)
{
    $xmlW->writeElement('Id', $i);
}

$xmlW->endElement();
$xmlW->endElement();

$output = $xmlW->flush();

// Either this
$client->GetPaymentByTransactionId($output);

// Or maybe this
$client->GetPaymentByTransactionId(array($output));
?>

Was This Post Helpful? 0
  • +
  • -

#5 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

Re: PHP and Soap Client - Multi-Level Array as Argument

Posted 28 May 2012 - 01:37 PM

View PostCTphpnwb, on 28 May 2012 - 12:53 PM, said:

This doesn't look right:
<ns1:XmlIds>Array</ns1:XmlIds>

What happens if you use this?
$trx = $client->GetPaymentByTransactionId('61080');


Yea, the "Array" is what I think is killing it for me.

Tested this originally, gives similar result. Here is the generated XML Request (Missing ID Now)
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.harms-software.com/Millennium.SDK"><SOAP-ENV:Header><ns1:MillenniumInfo><ns1:MillenniumGuid>xxx-xxx-xxx-xxx</ns1:MillenniumGuid></ns1:MillenniumInfo><ns1:SessionInfo><ns1:SessionId>a68803a4-a14b-48dc-81fd-61929fb2bb0b</ns1:SessionId></ns1:SessionInfo></SOAP-ENV:Header><SOAP-ENV:Body><ns1:GetPaymentByTransactionId/></SOAP-ENV:Body></SOAP-ENV:Envelope> 


And same when I tested both of your examples JackOfAllTrades.
I displayed the XML output from your code and it gives me the correct format, but it does not show in the Last Request and causes Server error still.

When I put the string version of the XML it changes it to html entities and becomes invalid >.<

This post has been edited by VolcomMky: 28 May 2012 - 01:38 PM

Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,435
  • Joined: 23-August 08

Re: PHP and Soap Client - Multi-Level Array as Argument

Posted 28 May 2012 - 01:42 PM

Oh, wait...it's even more fucked up than I realized.

$xmlW->startElement('MyIdList');
for($i = 1; $i <= 5; ++$i)
{
	$xmlW->startElement('Ids');
	$xmlW->writeElement('Id', $i);
	$xmlW->endElement();
}

$xmlW->endElement();

Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,435
  • Joined: 23-August 08

Re: PHP and Soap Client - Multi-Level Array as Argument

Posted 28 May 2012 - 03:39 PM

Quote

When I put the string version of the XML it changes it to html entities and becomes invalid >.<


Last suggestion, per this quote, you could try wrapping it in CDATA tags:

<?php

$xmlW = new XMLWriter();
$xmlW->openMemory();

$xmlW->startCData();
$xmlW->startElement('MyIdList');
for($i = 1; $i <= 5; ++$i)
{
	$xmlW->startElement('Ids');
	$xmlW->writeElement('Id', $i);
	$xmlW->endElement();
}

$xmlW->endElement();
$xmlW->endCData();
print $xmlW->flush();

// Either this
//$client->GetPaymentByTransactionId($xmlW->outputMemory());

// Or maybe this
//$client->GetPaymentByTransactionId(array($xmlW->outputMemory()));
?>


Seriously...it is FUCKED UP to take an XML string as a parameter to a SOAP function.
Was This Post Helpful? 0
  • +
  • -

#8 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

Re: PHP and Soap Client - Multi-Level Array as Argument

Posted 29 May 2012 - 10:00 AM

So I have tested your suggestions and it is still not including the ID's in the request.

And I agree, agree VERY much, about how fucked up this is. lol

I can get all other functions/calls to work except for the ones that require the ID Lists, which sucks cause do get detailed information I need to pull by ID, and even if your looking for a specific ID, it requires the XML format

FML :taz:
Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,435
  • Joined: 23-August 08

Re: PHP and Soap Client - Multi-Level Array as Argument

Posted 29 May 2012 - 10:30 AM

Contact the SDK provider, they should be able to provide you with an example that works.
Was This Post Helpful? 0
  • +
  • -

#10 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

Re: PHP and Soap Client - Multi-Level Array as Argument

Posted 29 May 2012 - 10:44 AM

If I don't use the array as an argument it won't display in the request.

So I thought about mixing both ideas, use the array and the code supplied JackOfAllTrades

Here is the sent request:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.harms-software.com/Millennium.SDK"><SOAP-ENV:Header><ns1:MillenniumInfo><ns1:MillenniumGuid>xxx-xxx-xxx-xxx</ns1:MillenniumGuid></ns1:MillenniumInfo><ns1:SessionInfo><ns1:SessionId>e0fd7a69-dbe0-488d-a6b5-7b18e644b6fe</ns1:SessionId></ns1:SessionInfo></SOAP-ENV:Header><SOAP-ENV:Body><ns1:GetPaymentByTransactionId><ns1:XmlIds>&lt;![CDATA[&lt;Ids&gt;&lt;Id&gt;61080&lt;/Id&gt;&lt;/Ids&gt;]]&gt;</ns1:XmlIds></ns1:GetPaymentByTransactionId></SOAP-ENV:Body></SOAP-ENV:Envelope> 


And here is the code I used for this request:
$xmlID = new XMLWriter();
$xmlID->openMemory();
$xmlID->startCData();
$xmlID->startElement('Ids');
$xmlID->writeElement('Id','61080');
$xmlID->endElement();
$xmlID->endCdata();
$id_xml = $xmlID->flush();
		
$trx = $client->GetPaymentByTransactionId(array('XmlIds'=>$id_xml));


The XML is proper
<![CDATA[<Ids><Id>61080</Id></Ids>]]>


Do you think I should look into using SoapParam ?

I am going to be calling them today, we paid for support but I just hope they don't just tell me to look at the documentation... Cause it sucks.. :nottalkingtoyou:

This post has been edited by VolcomMky: 29 May 2012 - 10:44 AM

Was This Post Helpful? 0
  • +
  • -

#11 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,435
  • Joined: 23-August 08

Re: PHP and Soap Client - Multi-Level Array as Argument

Posted 29 May 2012 - 12:04 PM

You could try qualifying the Ids and Id tags with ns1 via the XmlWriter's startElementNS and writeElementNS functions.

Sucky documentation is a killer.
Was This Post Helpful? 0
  • +
  • -

#12 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

Re: PHP and Soap Client - Multi-Level Array as Argument

Posted 29 May 2012 - 12:43 PM

Yea, when programming with GoDaddy's Reseller and Plesk, it was a major headache cause it's documentation was WAY off. So off people were paying 100's for someone do give them a starter API to get certified.

BUT
I am on the Client Community Forums for the SDK and there was someone with a similar problem.

They only issue with theirs was a invalid character in the XML, but what they called is just as a string. So now I am a little more stumped.

Here is what they have
Dim ids As String = "<Body Care Retail><Ids><Id>94</Id></Ids></Body Care Retail>"
xmlDataSource1.Data = SoapClient.GetProductListingByClass(ids, False, False)


Granted they are doing it in what appears to be VB (I think) and calling a different function.

The ID's argument is of similar format and they got it to work with the above. So I tested it in the same format on my PHP script and it still failed.
Was This Post Helpful? 0
  • +
  • -

#13 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

Re: PHP and Soap Client - Multi-Level Array as Argument

Posted 29 May 2012 - 01:12 PM

And......

I tested using cURL so I could format the XML as needed
$RAW = '<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.harms-software.com/Millennium.SDK"><SOAP-ENV:Header><ns1:MillenniumInfo><ns1:MillenniumGuid>xxx-xxx-xxx-xxx</ns1:MillenniumGuid></ns1:MillenniumInfo><ns1:SessionInfo><ns1:SessionId>caed8cf8-d1b9-407c-b9c7-6cf099368445</ns1:SessionId></ns1:SessionInfo></SOAP-ENV:Header><SOAP-ENV:Body><ns1:GetPaymentByTransactionId><ns1:XmlIds><Id>61080</Id></ns1:XmlIds></ns1:GetPaymentByTransactionId></SOAP-ENV:Body></SOAP-ENV:Envelope> ';

$c = curl_init();
curl_setopt($c, CURLOPT_URL, $soapClientWSDL);
curl_setopt($c, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","charset=utf-8"));
curl_setopt($c, CURLOPT_HEADER, 1);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $RAW);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$r = curl_exec($c);
curl_close($c);


And with <Ids></Ids>, it gives a 400 BAD REQUEST, Without - I get the Invalid XML List error like I have been..

I am emailing the SDK Support now and will post an update if people are interested in their off the wall solution.
Was This Post Helpful? 0
  • +
  • -

#14 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,435
  • Joined: 23-August 08

Re: PHP and Soap Client - Multi-Level Array as Argument

Posted 30 May 2012 - 02:51 AM

I would be curious to hear what the issue is. Hope you can get it sorted.

I've been working with a crappy SOAP API, but it's not crappy in how it was designed, just how what's on the other side of the SOAP is implemented. Round-trip city.
Was This Post Helpful? 0
  • +
  • -

#15 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

Re: PHP and Soap Client - Multi-Level Array as Argument

Posted 30 May 2012 - 11:06 AM

Okay so so far, the support has givin me 2 fixes.

Neither of which have worked, first they gave me a Class for the SDK that another client has written.

That's cool and all and it works, but doesn't fix my issue because it only contains a few functions, neither of which use a ID List, so doesn't help.

Second, I was asked to test this
$client->GetPaymentByTransactionId('<XmlIds><Ids><Id>61080</Id></Ids></XmlIds >'));

(Which is invalid cause of a extra ), so removing that, I get the same error I have been getting and the XML is missing from the request.

Just an update!
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2