Jump to content

Complex data required for SoapParams


themistral

Recommended Posts

Hiya,

 

I was cruising along with SOAP nicely until I needed to parse more complex xml in a soapcall.

I am using non-wdsl if that makes any difference.

 

I need to create XML in the following structure:

 

<Body>
  <SOAP_updateCreateContactMarketingRule>
    <Contact_ID xsi:type="xsd:int">1</Contact_ID>
    <MarketingRule_ID xsi:type="xsd:int">1</MarketingRule_ID>
    <MarketingQuestions>
      <MarketingQuestion>
        <MarketingQuestion_ID xsi:type="xsd:int">1</MarketingQuestion_ID>
        <Answer xsi:type="xsd:string">No</Answer>
      </MarketingQuestion>
      <MarketingQuestion>
        <MarketingQuestion_ID xsi:type="xsd:int">2</MarketingQuestion_ID>
        <Answer xsi:type="xsd:string">Yes</Answer>
      </MarketingQuestion>
    </MarketingQuestions>
  </SOAP_updateCreateContactMarketingRule>
</Body>

 

 

So, I set my parameters up as follows:

 

$params[] = new SoapParam("1", "Contact_ID");

$params[] = new SoapParam("1", "MarketingRule_ID");

$params[] = new SoapParam(array("MarketingQuestion"=>array("MarketingQuestion_ID"=>1, "Answer"=>"Yes")), "MarketingQuestions");

 

And I am getting the following XML generated when I use __getLastRequest()

 

<SOAP-ENV:Body>
<ns1:SOAP_updateCreateContactMarketingRule>
	<Contact_ID xsi:type="xsd:string">1</Contact_ID>
	<MarketingRule_ID xsi:type="xsd:string">1</MarketingRule_ID>
	<MarketingQuestions SOAP-ENC:arrayType="ns2:Map[1]" xsi:type="SOAP-ENC:Array">
		<item xsi:type="ns2:Map">
			<item>
				<key xsi:type="xsd:string">MarketingQuestion_ID</key>
				<value xsi:type="xsd:int">8</value>
			</item>
			<item>
				<key xsi:type="xsd:string">Answer</key>
				<value xsi:type="xsd:string">Yes</value>
			</item>
		</item>
	</MarketingQuestions>
</ns1:SOAP_updateCreateContactMarketingRule>
</SOAP-ENV:Body>

 

 

Clearly my third parameter is not set up correctly - can anyone help with this?

 

Thanks  :D

Link to comment
https://forums.phpfreaks.com/topic/255272-complex-data-required-for-soapparams/
Share on other sites

You need to create object instead of array!

 

<?php
class mQuestion
{
   public MarketingQuestion_ID;
   public Answer
}

$question1 = new mQuestion();
$question2 = new mQuestion();

$question1->MarketingQuestion_ID = 1;
// fill other fields ...

$client->__soapCall("SomeFunction", array($question1, $question1));
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.