Solved

PHP-SOAP; Problem with Passing Array

Posted on 2010-09-19
3
1,094 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

635 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