Solved

PHP-SOAP; Problem with Passing Array

Posted on 2010-09-19
3
1,043 Views
Last Modified: 2012-05-10
Greetings Experts,

I am trying to write a PHP script to integrate with an on-line service called Agemni. My problem, in a nutshell, is that I need to pass an array of items to the SOAP server Unfortunately I have no idea how to do that. I am quite new to using SOAP with PHP. The applicable part of the WSDL is below the part I'm having trouble with are the keys\values of type "tns:ArrayOfAnyType". I need to pass an array consisting of keys  fname, lname and phone initially to test.

      <s:element name="CreateEntity">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="strUsername" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="strPassword" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="strCompanyName" type="s:string" />
            <s:element minOccurs="1" maxOccurs="1" name="objecttype" type="s:int" />
            <s:element minOccurs="0" maxOccurs="1" name="keys" type="tns:ArrayOfAnyType" />
            <s:element minOccurs="0" maxOccurs="1" name="values" type="tns:ArrayOfAnyType" />
          </s:sequence>
        </s:complexType>
      </s:element>

Open in new window


Here is the code I have written so far.

<?php

// Define Variables

   $wsdl = "http://agemni.com/AgemniWebservices/service1.asmx?WSDL";

// Define array

   $parameters['parameters']['strUsername']     = "";
   $parameters['parameters']['strPassword']     = "";
   $parameters['parameters']['strCompanyName']  = "";
   $parameters['parameters']['objecttype']      = 2;
   $parameters['parameters']['keys']            = ;
   $parameters['parameters']['values']          = ;

// Fetch Dishstar WSDL
// Note WSDL caching of TTL 86400 seconds is enabled in php.ini for performance

   $client = new SoapClient($wsdl, array('trace' => 1));
   
// Make SOAP Call in WSDL mode

   try {
     $result = $client->__soapCall("CreateEntity", $parameters);

   } catch (SoapFault $fault) {
    trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
   }
    
// Display results of SOAP call
    
   var_dump($result);
            
   echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
            
?>

Open in new window


Finally here is a link to documentation for the API.
Leads and Customer API


Any help on this issue would be greatly appreciates. Thank you in advance for your assistance!
0
Comment
Question by:rwterp
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
upandrun3 earned 500 total points
ID: 33713243
Hi rwterp,

I'm guessing you're not getting any type of response back from your request?

If it's using the WSDL, have you tried something like this:

$username = "";
$password = "";
$company_name = "";
$object_type = 2;
$keys = array("fname","lname","phone");
$values = array("Bob","Roberts","555-555-5555");

$client = new SoapClient($wsdl, array('trace' => 1));
$result = $client->CreateEntity($username,$password,$company_name,$object_type,$keys,$values);

// You can put the test and such around this and var_dump the results.

Note, I haven't tested this and it may take some tweaking.

Hope it helps,
Pete
0
 

Author Comment

by:rwterp
ID: 33713262
Pete,

Actually I am getting a response. I tried your suggestion although in a slightly different fashion and it seems to have resolved the problem. Unfortunately it introduced another problem. I'm receiving this response from the SOAP Server

string(63) "Conversion from type 'XmlNode()' to type 'String' is not valid."
 
  $KeyList    = array("phone", "fname", "lname" ,"area id","lead id","contactdate");



  $ValueList  = array("9495551212","james","bond","1","2","9/19/2010");





   $parameters['parameters']['strUsername']     = "";

   $parameters['parameters']['strPassword']     = "";

   $parameters['parameters']['strCompanyName']  = "";

   $parameters['parameters']['objecttype']      = 2;

   $parameters['parameters']['keys']            = $KeyList  ;

   $parameters['parameters']['values']          = $ValueList  ;

Open in new window

0
 

Author Closing Comment

by:rwterp
ID: 33713279
The response fully resolved the posted question.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now