Solved

PHP-SOAP; Problem with Passing Array

Posted on 2010-09-19
3
1,034 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

708 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

10 Experts available now in Live!

Get 1:1 Help Now