Solved

php soap wsdl array of complextype

Posted on 2014-01-13
15
4,049 Views
Last Modified: 2016-02-26
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");
$server->AddFunction("doProcessData");
$server->handle();


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!
0
Comment
Question by:flowerbloom
  • 7
  • 4
  • 4
15 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39779463
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.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12239-Introduction-to-Application-Programming-Interfaces.html

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.
0
 
LVL 1

Author Comment

by:flowerbloom
ID: 39779678
Thanks for the response Ray, but it is not an option.  Please provide a solution according to my environment.

Thanks!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39779871
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.
0
 
LVL 33

Expert Comment

by:Slick812
ID: 39780068
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 -
     http://www.phpeveryday.com/articles/Web-Services-WSDL-Anatomy-of-WSDL-Document-P477.html

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? ?
0
 
LVL 1

Author Comment

by:flowerbloom
ID: 39780233
I think what I need is something like the solution here:
http://stackoverflow.com/questions/2293873/how-do-i-define-an-array-of-custom-types-in-wsdl

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.
0
 
LVL 1

Author Comment

by:flowerbloom
ID: 39780241
... also:
http://www.phpeveryday.com/pack/Web-Services-WSDL-Array-Step-By-Step-Tutorial

I think I need to combine the two top topics and have array of objects.  your thoughts?
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39780301
@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
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:flowerbloom
ID: 39780463
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.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39780494
Understood.  Best of luck with it, ~Ray
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 500 total points
ID: 39780529
XML code at http://stackoverflow.com/questions/229387 -
<xs:schema elementFormDefault="qualified" 
           targetNamespace="http://schemas.datacontract.org/2004/07/Foo" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           xmlns:tns="http://schemas.datacontract.org/2004/07/Foo">
    <xs:complexType name="ArtPiece">
        <xs:sequence>
            <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:sequence>
    </xs:complexType>

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

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

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

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 -
<xs:complexType
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">
        <xs:sequence>

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.
0
 
LVL 1

Assisted Solution

by:flowerbloom
flowerbloom earned 0 total points
ID: 39780627
I think I got it.  The first "element" is just ONE object (complextype).  The second "element" is an array of objects.

Please confirm.

Thanks.
0
 
LVL 33

Assisted Solution

by:Slick812
Slick812 earned 500 total points
ID: 39780679
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
xs:int
xs:string

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
0
 
LVL 1

Author Closing Comment

by:flowerbloom
ID: 39791956
It is part of the solution
0
 
LVL 33

Expert Comment

by:Slick812
ID: 39794955
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.
0
 
LVL 1

Author Comment

by:flowerbloom
ID: 39795373
Thanks. I'm looking for something simple.
0

Featured Post

Highfive Gives IT Their Time Back

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This article discusses how to create an extensible mechanism for linked drop downs.
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

12 Experts available now in Live!

Get 1:1 Help Now