R: [phpxmlrpc] Problems with example (first webservice)
Gaetano Giunta
giunta.gaetano at sea-aeroportimilano.it
Wed Nov 24 05:41:30 PST 2004
I pasted your code on my webserver (brr.....) and it worked OK.
Hints:
1 - what the xmlrpc caller is getting IS NOT valid XML (the mesage tells you that)
2 - it's probably due to an error in the xmlrpc server page. If you have error_diplay = ON in PHP.INI, the php error will be printed to the web server page, which in this case is the XML that the client expects to receive.
3 - use $client->setDebug(true); to have the client dump to screen (to the web browser) the garbage it is receiving from the server.
4 - since the code you're writing is quite short, I suspect the directory where you dumped xmlrpc.inc and xmlrpcs.inc is not in your include path...
bye
Gaetano
> -----Messaggio originale-----
> Da: phpxmlrpc-bounces at usefulinc.com
> [mailto:phpxmlrpc-bounces at usefulinc.com]Per conto di keroppi kero
> Inviato: giovedì 18 novembre 2004 19:59
> A: phpxmlrpc at usefulinc.com
> Oggetto: [phpxmlrpc] Problems with example (first webservice)
>
>
> I installed IIS in my windows. Then I installed PHP (4.3.9 by
> installer). I
> tryed php pages and it wokk fine.
>
> Then I put xmlrpc for php directory in D:\Inetpub\wwwroot\php .
> Afeter this I create two files:
>
> sample.php:
> <?php
> include 'xmlrpc.inc';
> include 'xmlrpcs.inc';
>
> function sumAndDifference ($params) {
>
> // Parse our parameters.
> $xval = $params->getParam(0);
> $x = $xval->scalarval();
> $yval = $params->getParam(1);
> $y = $yval->scalarval();
>
> // Build our response.
> $struct = array('sum' => new xmlrpcval($x + $y, 'int'),
> 'difference' => new xmlrpcval($x -
> $y, 'int'));
> return new xmlrpcresp(new xmlrpcval($struct, 'struct'));
> }
>
> // Declare our signature and provide some documentation.
> // (The PHP server supports remote introspection. Nifty!)
> $sumAndDifference_sig = array(array('struct', 'int', 'int'));
> $sumAndDifference_doc = 'Add and subtract two numbers';
>
> new xmlrpc_server(array('sample.sumAndDifference' =>
> array('function' => 'sumAndDifference',
> 'signature' =>
> $sumAndDifference_sig,
> 'docstring' =>
> $sumAndDifference_doc)));
> ?>
>
> and sumAndDifference2.php:
> <html>
> <head>
> <title>XML-RPC PHP Demo</title>
> </head>
> <body>
> <h1>XML-RPC PHP Demo</h1>
>
> <?php
> include 'xmlrpc.inc';
>
> // Make an object to represent our server.
> $server = new xmlrpc_client('/php/sample.php',
> 'localhost', 80);
>
> // Send a message to the server.
> $message = new xmlrpcmsg('sample.sumAndDifference',
> array(new xmlrpcval(5, 'int'),
> new xmlrpcval(3, 'int')));
> $result = $server->send($message);
>
> // Process the response.
> if (!$result) {
> print "<p>Could not connect to HTTP server.</p>";
> } elseif ($result->faultCode()) {
> print "<p>XML-RPC Fault #" . $result->faultCode() . ": " .
> $result->faultString();
> } else {
> $struct = $result->value();
> $sumval = $struct->structmem('sum');
> $sum = $sumval->scalarval();
> $differenceval = $struct->structmem('difference');
> $difference = $differenceval->scalarval();
> print "<p>Sum: " . htmlentities($sum) .
> ", Difference: " . htmlentities($difference) . "</p>";
> }
> ?>
> After this I put xmlrpc.inc and xmlrpcs.inc into
> D:\Inetpub\wwwroot\php
>
> After this I opened browser (IE) and enter
> localhost/php/sumAndDifference2.php, then execute and recibe
> this message:
>
> XML-RPC PHP Demo
> XML error: junk after document element at line 2
> XML-RPC Fault #2:
>
> I don't understand why it doesn't work.
>
> Anyone knows what is my mistake?
>
> Please help me, I tryed make a webservice and I can not begin it.
>
> Thanks for you attention, keroppi.
>
> _________________________________________________________________
> La información más fresca desde diferentes puntos de vista en
> la Revista de
> Prensa de MSN. http://es.newsbot.msn.com/
>
>
> _______________________________________________
> phpxmlrpc mailing list
> phpxmlrpc at usefulinc.com
> http://lists.usefulinc.com/cgi-bin/mailman/listinfo/phpxmlrpc
More information about the phpxmlrpc
mailing list