php soap wsdl array of complextype

Using PHP, I would like to send multiple records at once to a SOAP server to be processed and the respondent to be in some XML format for multiple responses.

I think the way to go is using "PHP" => "soap / wsdl" => "array of complextype".

My thoughts for the CLIENT code will be:

$res_db = db_exec...();
$my_data = array();
while ($table_row = fetch_array_...($res_db);) {
  $id = $table_row['id'];
  $name = $table_row['name'];
  $my_data[] = array('id' => $id, 'name' => $name);

$soap_client = new SoapClient('http://my_server/my.wsdl');
$response = $soap_client->doProcessData($my_data);

My thoughts for the SERVER code will be:

function doProcessData($my_data) {
  $response= array();
  foreach ($my_data as $k => $data) {
    $id = $data['id'];
    $name = $data['name'];
    // Process data and either succeed or fail
    $response[] = array('id' => $id, 'error_code' => $error_code, 'error_message' => $error_message);

  $xml = new SimpleXMLElement('<ProcessResponse/>');
  array_walk_recursive($response, array ($xml, 'addChild'));
  return $xml->asXML(); // Return the XML as String

$server = new SoapServer("my.wsdl");

I need some babysitting on this, so please have detailed explanations and examples of:
1. Code for soap client and server (if differ from my suggestions).
2. The wsdl to be used (I think that is the hardest part for me).
3. The XML response to be used (I think that is the second hardest part for me).

PHP version is 5.2.6

Thank you!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
First step is probably to upgrade PHP, and do it ASAP.  PHP 5.2 is not supported any more, not even for security fixes!  It's been obsolete for a few years!

Next step, please read this article about APIs.  I think you want to avoid SOAP like the plague.  A RESTful interface is many times easier to get right.

You can send any amount of data you want via a POST-method request to a RESTful interface.  The REST API can read the raw post data, however it might make more sense to send the data in a JSON string.  PHP has json_decode() to help with that.  The REST API can return an XML string if you really want that, but a JSON string would probably make more sense today.
flowerbloomAuthor Commented:
Thanks for the response Ray, but it is not an option.  Please provide a solution according to my environment.

Ray PaseurCommented:
Have you read the API article?  The principles in the article will probably all work correctly even if you're stuck on an obsolete version of PHP.  What I can't help with is SOAP -- it is just a technological nightmare, which is why Google, Yahoo, and most other major web entities have abandoned it.
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

greetings  flowerbloom, , I will say some here about the design Specs you have given. I can not be considering any code thinking at this point. It looks like you are starting to design your own web server data distribution using the client-dataSource communication protocol as WSDL-Soap. This can be a useful protocol for more complex data retrievals, with many client options, changed by the data sent to the client, in a muti-step data filtering-sorting process, , , or at least that my view of it. The center of the client-dataSource communication would likely be the  Web Services description Language (WSDL) of your Data and function definitions in XML. This can be a major DIFFICULT-LONGTIME development trial and error effort and head ache, if you start from scratch.  Here is some valuable information that may help you, , about the "Text" of the XML content used in wsdl -

There much other helpful info there about WSDL, and it more or less shows you how to "Think" in development of your WSDL interface, and the DATA types and FUNCTION operations-definitions. If you are going to develop this for profit, and you have little experience in WSDL client-dataSource communication, You may should try and find someone (consultant) that has experience in this, as the subtleties and small factors can be a time consuming development drag.

Inter-Server Web data transfer now is FASTER than it used to be, so as Ray has pointed out, A muti-step data filtering process can be handled now with a more static client-dataSource transaction, like a REST thing. The API for client  data access  can be defined in a web document, so instead of having "Functions", ,  you have different web-address access, that acts as the server function to process the client INPUTS and sends the result back as DATA from the Function processing on the source server. The client uses the DATA sent back, and if further dataSource processing or data retrieval is needed, then another dataSource web address is used as a dataSource function to do more with the NEW client INPUTS. Likely this static API can be more easy to develop? ? But There are a TON of factors to consider in any client-dataSource communication. One may be the Difficultly a client developer in understanding the WSDL setup you produce, Like You when you say -
     The wsdl to be used (I think that is the hardest part for me).
Others are NOT likely to spend time to figure out your WSDL implementation , even if you produce a LARGE explanation of your API.

Just to see, use the above "Anatomy-of-WSDL-Document" pages tutorial, and set up a Simple WSDL-Soap thing, and experiment with data types and function calls, and see if you are up to the task. Personally, I would hope I had a development team to get all of the design and setup work done for a new WSDL thing, or you may just run out of time? ?
flowerbloomAuthor Commented:
I think what I need is something like the solution here:

Please let me know (simply and with details) if this applies to what I'm looking for and, if you may, an example.

Thank you.
flowerbloomAuthor Commented:
... also:

I think I need to combine the two top topics and have array of objects.  your thoughts?
Ray PaseurCommented:
@flowerbloom: No disrespect meant, but please don't build your application using SOAP.  The API article shows you exactly how to create the server-to-server applications.  You can send and receive JSON strings or XML documents, and these can represent any kind of data you need to communicate.  If you have any questions about the article contents, please post back and I'll try to clarify.

If you read the article and you still don't know how to do this it might be a good time to hire a professional developer, especially if you insist on doing it with SOAP.  I only say that because it's not really a question with an answer (the article has the answers) so much as a research and application development project, and for that you would want the services of a professional developer.

Best regards, ~Ray
flowerbloomAuthor Commented:
Hi Ray,

WSDL is not my choice.  Heck, I would move CSV files instead or use X12.  It is not a choice for me.

Thank you for your time.
Ray PaseurCommented:
Understood.  Best of luck with it, ~Ray
XML code at -
<xs:schema elementFormDefault="qualified" 
    <xs:complexType name="ArtPiece">
            <xs:element minOccurs="0" name="image" nillable="true" type="xs:base64Binary"/>
            <xs:element minOccurs="0" name="imageId" type="xs:int"/>
            <xs:element minOccurs="0" name="title" nillable="true" type="xs:string"/>
            <xs:element minOccurs="0" name="year" nillable="true" type="xs:string"/>

    <xs:element name="ArtPiece" nillable="true" type="tns:ArtPiece"/>

    <xs:complexType name="ArrayOfArtPiece">
            <xs:element minOccurs="0" maxOccurs="unbounded" name="ArtPiece" nillable="true" type="tns:ArtPiece"/>

    <xs:element name="ArrayOfArtPiece" nillable="true" type="tns:ArrayOfArtPiece"/>

Open in new window

The entire purpose of XML is to have normal ascii TEXT used to set, define, partition, group, have boundaries for DATA, this was done in a BINARY way for program development and disk storage. XML is suppose to give you the Freedom in plain text, to do whatever is needed for COMPLEX data segments to be used when transferred or stored.  here in the -
the WSDL definition of a ArrayOfArtPiece, here it also tell you what "element" TYPE as ArtPiece can be INSIDE this container

I am not an expert in the WSDL, but you have to define your unusual, non-standard DATA types in a WSDL syntax. Just because it has "Array" in its name as ArrayOfArtPiece, DOES NOT give it any ARRAY properties, you give the possibility of many elements, that can change by adding them,  in this container with the -
     minOccurs="0" maxOccurs="unbounded"

look at the container definition for -
<xs:complexType name="ArtPiece">

This ALWAYS has 4 elements an integer, 2 strings, and one base64Binary

BUT the ArrayOfArtPiece TYPE can have any number of ArtPiece TYPES as elements added to that container.

if you can not see "Idea of Formatting" this in the XML, you may should keep looking at the WSDL examples on the web till you, get some handle how this works, sorry I do not have the time today to write a tutorial for you.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
flowerbloomAuthor Commented:
I think I got it.  The first "element" is just ONE object (complextype).  The second "element" is an array of objects.

Please confirm.

Yes, what you say is true, BUT, the complextype , does NOT mean much as to what it can contain, Maybe a better term would be "specialtype" or "you-define-it-type", and usually it is something with many parts-elements, and some complexity. If you can plaese study the "standard" WSLD types like

the complextype is like Structures in C code, and Records in Pascal code, where unlike PHP you have to DEFINE your Data TYPE, if it is NOT standard, like int, string
flowerbloomAuthor Commented:
It is part of the solution
OK, thanks for points,
I feel like I should say a little more here -
I did not post code because the SOAP communication using the XML with delegations using a NameSpace division and other sub-ordering schemes , is very complex, with a reason, this can be used in some VERY, VERY COMPLEX inter-server communications for data transfer in an ordered step-wise calling of functions for several DIFFERENT server language (jsp, asp, php, ruby, cgi). . .  so the XML needs to be flexible and yet precise to handle the specific Functions, with Complex Data  AND  be usable in several calling platforms, some that are Object-Oriented only like JSP , I did not mention that in PHP you can use Class-Object and need to bind functions in the SOAP XML. If you are not familiar with programming terms like "bind" and their use in the Soap environment, then this may be something you may need to learn? This is all to much complexity for me to deal with in trying to tell you what to do for a PHP Soap web application, sorry.
flowerbloomAuthor Commented:
Thanks. I'm looking for something simple.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.