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
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));
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.