Solved

PHP-SOAP; Problem with Passing Array

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
The viewer will learn how to dynamically set the form action using jQuery.

821 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