Forum Moderators: coopster

Message Too Old, No Replies

querying a soap resource using php

general help needed

         

Oliver Henniges

1:46 pm on Mar 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just came across an interesting resource, which offers to let its database be queried by a soap interface.

I have a wamp-installation with php 5.0.5, so first I enabled the php-soap.dll in php ini, but a short test-file gave the error that no connection could be established. So, alternatively I disabled that again (restarting apache), and tried including the nusoap class, which seemed to have at least got proper access to that website.

But what next?

I tried

<?php
require_once('nusoap/lib/nusoap.php');
$sourceurl='http://my.resource.wsdl';
$client = new SoapClient($sourceurl);
if($sError = $client->getError()){ echo "Error: ". $sError;}
else{var_dump($client->__getFunctions());}
?>

and obviously no error had occured, but the php-answer was:

Call to undefined method soapclient::__getFunctions()

I thought this method would display me the possible query-parameters allowed on that website? How can I find out about that? Note that I only want to use my installation as a client, not as a server, but most tutorials on this matter explain the latter.

Any help is well appreciated.

Oliver Henniges

8:16 am on Mar 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, I admit there was a typing-mistake in the URL, which I fixed now.

getFunctions() gives this answer:

array(2) { [0]=> string(44) "executeResponse execute(execute $parameters)" [1]=> string(35) "pingResponse ping(ping $parameters)" }

getTypes() gives this answer:

array(8) { [0]=> string(58) "struct execute { RequestParameter objRequestParameters; }" [1]=> string(46) "struct DataMatrix { DataVector dataVectors; }" [2]=> string(67) "struct RequestParameter { string corpus; DataMatrix parameters; }" [3]=> string(60) "struct executeResponse { ResponseParameter executeReturn; }" [4]=> string(130) "struct ResponseParameter { string executionTime; DataMatrix result; int serviceMagnitude; int userAmount; int userMaxLimit; }" [5]=> string(15) "struct ping { }" [6]=> string(43) "struct pingResponse { string pingReturn; }" [7]=> string(38) "struct DataVector { string dataRow; }" }

Now what do I do with these arrays?
Sometimes I think I'm getting old: Still thinking in "procedures", not "objects";)

Somewhere else I read, that the google api is also working on basis of a soap interface. My first impression with this field is that exchange of such data-objects between servers will play an important role in future information retrieval in general. Wikipedia says it is part of ajax. Is this framework already covered on broader, more programmer-friendly abstraction-levels and thus not necessarily worth learning?

The documentation in the php-manual is not well elaborated and some introductions I found take the babelfish-service as an example, which is no longer supported at present.

cameraman

5:48 pm on Mar 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've only had one [irritating] foray into SOAP, which is why I didn't respond to this thread previously. The site I was working with had a WSDL file which is sort of the instruction sheet for your script.

It looks to me from your second post that you still don't have quite enough information to proceed - possibly dig around looking for further documentation?

I don't know the context of the statement you found; I couldn't find it - if you send me a sticky message with the url I'll go look at it (not that that would help you necessarily but just because I'm curious). I'm not disputing what the author said since I obviously haven't read it, but in general, SOAP and AJAX have nothing to do with each other. On the contrary, the SOAP paradigm is used to gather information from other servers while browser security (in firefox at least) frequently keeps AJAX requests limited to the server that the browser is pointed at.

My impression, and again, my experience is limited to one instance so this thought is predicated on my attempts at research during that experience, is that SOAP isn't being embraced and isn't likely to be widespread - I suppose it could be 'industry' specific; some groups may love the heck out of it, but personally I found it highly irritating and clunky to work with - it caused me 2 days of high agitation but failure wasn't an option. I probably am getting too old as well...

Little_G

6:19 pm on Mar 29, 2008 (gmt 0)

10+ Year Member



Hi, before I start I warn you I've also only had one [irritating] foray into SOAP as well.

The getFunctions() function returns an array of available soap calls, the getTypes() function returns an array of the complex data types defined by the server.
To recreate these complex types you need to put all the data in a multidemensional array that replicates the datatype's structure, so to call 'execute':

<?php
require_once('nusoap/lib/nusoap.php');
$sourceurl='http://my.resource.wsdl';
$client = new SoapClient($sourceurl);
$response = $client->call(
'execute',
array(
'objRequestParameters' => array(
'corpus' => 'corpus name here',
'parameters' => array(
'dataVectors' => array(
'dataRow' => 'data row goes here'
)
)
)
)
);
var_dump( $response );
?>

I think, though I can't test it so this may not work.

Andrew
[edit]Formatted code to stop horizontal scrolling[/edit]

[edited by: Little_G at 6:37 pm (utc) on Mar. 29, 2008]

Oliver Henniges

8:31 pm on Mar 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thxalot, guys.

> SOAP and AJAX have nothing to do with each other.

As I said, this is all new to me, but the german wikipedia-page on ajax (which seems far more complex than the english one) mentions soap as one of the layers involved for informaitonal interchange between servers. Compare

[de.wikipedia.org...]
[en.wikipedia.org...]

Little_G, meanwhile I managed to get php working without nusoap but the dll-extension instead. So first I had to change aour code to
client->__soapCall...
but it still did not work.

the error message was

"Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object hasn't 'objRequestParameters' property in ..."

Any ideas?

cameraman

9:01 pm on Mar 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't read German so I ran the page through babel-fish which was of course less than ideal. As near as I can figure, what they're saying is that when you make an AJAX request the server can use a variety of technologies to service the request. That is true. But I'm not seeing that the article is saying that either one is part of the other.

If you look closely at those unordered lists, the statement (translated) "An Ajax application is based on the following Web techniques" has five items. SOAP is mentioned in the next two unordered lists, one of which is enumerating resources and one that is enumerating (I think - that didn't translate well) content you can send back.

Little_G

9:08 pm on Mar 29, 2008 (gmt 0)

10+ Year Member



Hi,

I can't be certain but I think the SOAP extension doesn't accept associative arrays so remove the string keys.

Andrew

Oliver Henniges

9:08 pm on Mar 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Little_G,

though your code didn't work for whatever reason, I found it quite likely and I think had tested similar things before. How did you so quickly resolve the necessary variables form the array I gave?

Are you sure mere arrays will work? shouldn't I define the Datamatrix and other parameters as classes from the very beginning, or is this irrelevant for a first test?

Little_G

9:12 pm on Mar 29, 2008 (gmt 0)

10+ Year Member



Hi,

It was just a case of following the type definitions, the execute function accepts an argument of type execute the execute scruct contains one (or more?) RequestParameter which in turn consists of a string and a DataMatrix, and so on.
The __soapCall method requires arguments to be in the form of an array.

Andrew

[edited by: Little_G at 9:13 pm (utc) on Mar. 29, 2008]

Oliver Henniges

10:49 pm on Mar 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



cameraman, yes, I also read it this way that soap is one of several alternatives within ajax for exchanging information between servers.

What I am wondering about is the question, whether it makes sense to dive deeper into it. It is not yet well documented in the php-manuals, nor anywhere else over the internet, and thus maybe a dead-end, meanwhile. The service I was talking about also offers a java.jar-executable for private use, but I have no experiences with java and php is the only programing language I currently concentrate on. I want to integrate those queries into more complex structures.

Little_G

>It was just a case of following the type definitions

yes, but I am wondering whether I have to decode the relevant arrays in my own brain or whether object-oriented modelling offers some sort of "designing" of these arrays via script. (E.G. perform the getFunctions() and getTypes() operations with one script, then design an html-form with the parameter names, and finally pass those variables to a CGI performing the final request).

Did you in your code oversee the difference between datamatrix and datavector? Isn't that another variabe-level like this:

array('objRequestParameters' => array(
'corpus' => 'de','parameters' => array(
'DataMatrix',array(
'dataVectors' => array(
'dataRow' => 'test')))));

(But this didn't work either)

> remove the string keys.

what do you man with that?

Little_G

12:34 am on Mar 30, 2008 (gmt 0)

10+ Year Member



Hi,

After a lot of hacking it turns out the correct array to send to the execute function is:

array(
'objRequestParameters' => array(
'corpus' => 'de',
'parameters' => array(
'dataVectors' => array(
array(
'dataRow' => array('Limit','32')
),
array(
'dataRow' => array('Wort','Beitrag')
)
)
)
)
)

I'm going to have a rest after that one!

Andrew

Oliver Henniges

11:04 am on Mar 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you very much, Little_G,

with this code and the snippet you mailed me, I finally got my first replies. Maybe the resources will be of some value for you, if you replace corpus by "en" and insert an english lexeme after 'wort'.

However, I am a bit disappointed of the result: This edu-website also offers a CGI-web-interface, where you may insert your requests as Get-Variables. My first impression is that this CGI-interface performs far better than this SOAP-solution, though it doesn't return a mere array: you'd have to extract your data from the returned html-page using some grep or other string-manipulations.

The whole project is really badly documented, thx again for extracting the required parameters from the alternative java.jar-file. I think that such an automatic information interchange between computers via plattform-independent object-oriented markup-languages is one of the most fascinating sectors at present, and I am really wondering why I have to find pout about the required parameters via sort of trial and error. This could be done better.

Little_G

11:35 am on Mar 30, 2008 (gmt 0)

10+ Year Member



Hi,

The knowledge gained will I'm sure be of use in the future. The only time I used SOAP with PHP before I had to give up on the php extension because I couldn't get it to work!
I agree the service desperately needs documentation, I can't see any mention anywhere of how the dataVectors should be constructed.
I think the reason that the CGI interface returns more information is that we only queried the 'RightNeighbours' service, whereas the CGI appears to present information from all of the services combined.

Andrew

[edited by: Little_G at 11:36 am (utc) on Mar. 30, 2008]

Oliver Henniges

12:55 pm on Mar 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I agree the service desperately needs documentation

To my current (limited) understanding of SOAP this is supposed to be part of the server-site implemetation. I'm wondering whether the getTypes() function could and should supply information on the requested (allowed) input-parameters.

> whereas the CGI appears to present information from all of the services combined.

you may limit this by tinkering the get parameters. But I was talking about performance: Currently I'm not sure whether it makes sense to continue my ideas using soap or instead simply use file() requests with varying get-variables and then exttact what I need with string-operations on the returned html-code. Could probably be quicker than this SOAP-stuff.

Little_G

1:15 pm on Mar 30, 2008 (gmt 0)

10+ Year Member



Hi,

I'm not sure which would be faster, it's probably worth doing some benchmarks. However, though the CGI might return information faster, having to extract strings from the HTML will significantly slow down the script.

Andrew

Oliver Henniges

1:30 pm on Mar 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> having to extract strings from the HTML will significantly slow down the script.

To my experience the bottleneck has always been the internet-connection (unless I run some scripts on my dedicated server). For instance, to extract a links-array using preg_match_all from 30kByte raw html-code takes only milliseconds.

This SOAP interface seems to report some queries taking two or three seconds, whereas most of those CGI-pages came as fast as google's mainpage. Even if a complex string-analysis takes half a second (which I doubt it will), that will be much faster.

Oliver Henniges

1:40 pm on Mar 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But analysing raw html code always bears the danger of design changes: Today I may take a <h3> tag as a needle for extrancting right-coocurrance of words, but this may easily be changed by the webamster of that page and then all my scripts won't work any more. This will surely not be the case with SOAP.

Little_G

3:25 pm on Mar 30, 2008 (gmt 0)

10+ Year Member



Hi,

That's true, it also worth double checking the website's terms of service, sometimes they don't like automatic scripts downloading their pages.

Andrew