XMLRPC showing -32601 error (using PHP)
Asked Answered
M

1

2

I have the following code...

<?php
include("lib/xmlrpc.inc");

$email='[email protected]';

$c=new xmlrpc_client("/register/index.php", "ws.myserver.com", 80);
$f=new xmlrpcmsg('existsEmail', array(new xmlrpcval($email, "base64")));
print "<pre>" . htmlentities($f->serialize( )) . "</pre>";

$r=$c->send($f);
$v=$r->value( );

if (!$r->faultCode( )) {
    print "Email is". $email . " is " .
          $v->scalarval( ) . "<br />";
          print "<hr />I got this value back<br /><pre>" .
          htmlentities($r->serialize( )). "</pre><hr />\n";
} else {
    print "Fault: ";
    print "Code: " . $r->faultCode( ) .
    " Reason '" .$r->faultString( )."'<br />";
}

?>

I need to consume the WebService located at http://ws.myserver.com/register/index.php.

I pass the email as a parameter and then the XMLRPC.inc library will encode it using base64.

I've got a good XML request shown below:

<?xml version="1.0"?>
<methodCall>
<methodName>existsEmail</methodName>
<params>
<param>
<value><base64>dnJvZHJpZ3VlekBpY2NrLm5ldC5jbw==</base64></value>
</param>
</params>
</methodCall>

BUUUT, when I tried to get a response from the server I've to the following error

Fault: Code: -32601 Reason 'server error. requested method not found'

Any ideas? I'm getting crazy about how to call the existsEmail method from my PHP code...I'm sure it is there but I don't know if I'm missing something..

Mcilroy answered 28/2, 2012 at 15:47 Comment(0)
M
2

You are getting an error message (Specification for Fault Code Interoperability, version 20010516) from the XMLRPC endpoint you're communicating with.

It is a defined error code:

-32601 ---> server error. requested method not found

The RPC method you requested was not found by the server. Contact the support of the service you consume to get a list of all available methods. If that method should be available, contact the support and discuss the issue with them.

You asked in comment:

Is there any way [to] verify which methods are available?

That depends on the service. XMLRPC on sourceforge has a suggestion of defined methods you can call to list information about the functions available:

XML-RPC Introspection

  • system.listMethods
  • system.methodSignature
  • system.methodHelp

You can try if it works with your service, too. AFAIK those are common, I wrapped up a quick example, you find the full code below. See the output below the code as well.

$path = 'http://xmlrpc-c.sourceforge.net/api/sample.php';

printf("\n XMLRPC Service Discovery\n\n for: '%s'\n\n", $path);

$discovery = new Discovery($path);
$methods = $discovery->getMethods();

printf(" Method Summary:\n ===============\n", count($methods));
foreach ($methods as $i => $method)
{
    printf(" %'.-2d %s\n", $i + 1, $method->getName());
}

printf("\n Method Details (%d):\n ===================\n", count($methods));
foreach ($methods as $i => $method)
{
    printf("  %'.-2d %s\n", $i + 1, $method->getName());
    printf("\n       %s\n", $method);
    printf("\n%s\n\n", preg_replace('/^/um', '     ', wordwrap($method->getHelp(), 46)));
}

Output:

 XMLRPC Service Discovery

 for: 'http://xmlrpc-c.sourceforge.net/api/sample.php'

 Method Summary:
 ===============
 1. debug.authInfo
 2. sample.add
 3. sample.sumAndDifference
 4. system.listMethods
 5. system.methodHelp
 6. system.methodSignature

 Method Details (6):
 ===================
  1. debug.authInfo

       <struct> debug.authInfo

     Report any HTTP authentication in use

  2. sample.add

       <int> sample.add (<int>, <int>)

     Add two numbers

  3. sample.sumAndDifference

       <struct> sample.sumAndDifference (<int>, <int>)

     Add and subtract two numbers

  4. system.listMethods

       <array> system.listMethods (<string>)

     This method lists all the methods that the
     XML-RPC server knows how to dispatch

  5. system.methodHelp

       <string> system.methodHelp (<string>)

     Returns help text if defined for the method
     passed, otherwise returns an empty string

  6. system.methodSignature

       <array> system.methodSignature (<string>)

     Returns an array of known signatures (an array
     of arrays) for the method name passed. If no
     signatures are known, returns a none-array
     (test for type != array to detect missing
     signature)

You can find the sourcecode here: XMLRPC Discovery Service

Munafo answered 28/2, 2012 at 15:52 Comment(3)
Thanks hakre...you think I'm not able to consume the webservice because there is something missing from them? I think it is alright.. is there any way I can verify which methods are available?Mcilroy
@Leo, I extended the answer. This might be the info you're looking for.Munafo
Hi Hakre... I found out was wrong.. I was missing the prefix to the method, it should be 'reg.existsEmail' and also the value is "string", nor "base64" because the Webservice hast to received an already coded string... Anyway, that help from your is AWESOME!!! I'll use it to verify some other features from my WS providerMcilroy

© 2022 - 2024 — McMap. All rights reserved.