Xml-rpc php python

I am attempting to use xml-rpc in python. I have been trying to set the headers correct for the client id. I see all kinds of examples for Soap but not for xml-rpc.
I have not even found any examples for PHP on how to use the PHP generated by RO.
I see how the PHP includes generated by RO is actually using xml-rpc.
I have the PHP interface and can see how it works however I have the same issue.
Not being able to send the proper client id with the request for RO sever to read and authenticate.

In the following code the Sum function requires me to pass the client id returned from the login service with the request to use it.
I cannot get the header right for the RO server to read it and say I am authenticated.
Here is my python code…

import xmlrpclib
from pprint import pprint

logininfo = []
sessionID = ‘’

from xmlrpclib import ServerProxy, Transport, Error

class SpecialTransport(Transport):
…def send_content(self, connection, request_body):
…global sessionID
…print ‘sess in transport=’+sessionID
…connection.putheader(“ROClientIDHeader”, sessionID)
…connection.putheader(“ROClientIDHeader”, ‘ID=’+sessionID)
…connection.putheader(“ROClientIDHeader:ID”, sessionID)
…connection.putheader(“ID”, sessionID)
…connection.putheader(“ID”, ‘ID=’+sessionID)
…connection.putheader(“Content-Type”, “text/xml”)
…connection.putheader(“Content-Length”, str(len(request_body)))
…connection.endheaders()
…if request_body:
…connection.send(request_body)

server = ServerProxy(“http://localhost:8099/xmlrpc/LoginService”, transport=SpecialTransport())
try:
…print server.LoginService.ServerLogin(‘23dashes’, ‘23dashes’, logininfo)
…logininfo = server.LoginService.ServerLogin(‘23dashes’, ‘23dashes’, logininfo)
…loginresult = logininfo[0]
…logininfodict = logininfo[1]
…if loginresult == True:
…print ‘login successfull’
…else:
…print ‘login failed’

…sessionID = logininfodict.get(‘SessionID’)
…print ‘sess=’+sessionID
…print server.CoreService.Sum(1,1)
except Error, v:
…print “ERROR”, v

I would love to see either PHP or Python code on how to call a function after being authenticated by a login service.
How am I to send the client id back to RO in the RPC call?

Here is my php code that I cannot get to work as well…

<?php require("AppServerLibrary_intf.inc"); $lservice = new LoginService('http://localhost:8099/xmlrpc'); $logininfo = new DTLoginInfo(); $isloggedin = $lservice->ServerLogin('23dashes', '23dashes', $logininfo); if ($isloggedin == TRUE){echo 'logged in';} else {echo 'not logged in';} foreach ($logininfo as $name => $value) { echo "$name: $value"; } //Call unprotected function in login service - works fine. echo $lservice->GetDSNName(); //Call protected function in another service - does not work! $service = new CoreService('http://localhost:8099/xmlrpc'); echo $service->Sum(15, 12); ?>

In this example the $logininfo variable that should be filled, all properties such as sessionid are empty.

Any help?

GOT IT!!
Contacted the RO Server Developer.
They had to set the property of sendsessionid to True on the Dispatcher component (TROXMLRPCmessage).
Then the following Python code works great…

import uuid
from xmlrpclib import ServerProxy, Transport, Error

logininfo = []
guid = uuid.uuid1()
sessionID = ‘{’+str(guid).upper()+’}’

server = ServerProxy(“http://localhost:8099/xmlrpc/LoginService”)
try:
…logininfo = server.LoginService.ServerLogin(sessionID, ‘23dashes’, ‘23dashes’, logininfo)
…sessionID = logininfo[0]
…loginresult = logininfo[1]
…if loginresult == True:
…print ‘login successfull’
…else:
…print ‘login failed’
…logininfodict = logininfo[2]
…print server.CoreService.Sum(sessionID, 5,5)[1]
…print server.CoreService.Sum(sessionID, 6,7)[1]
except Error, v:
…print “ERROR”, v

Sorry, PHP users, I still can’t get PHP to work.
I run into “Cannot pass parameter 3 by reference” in the ServerLogin method in PHP!
I wanted to post a PHP sample for the community, but I am not a PHP programmer.
If someone wishes to correct the following PHP code that would be awesome!

require(“AppServerLibrary_intf.inc”);
$sesid = com_create_guid();
echo $sesid;
$lservice = new LoginService(‘http://localhost:8099/xmlrpc’);
$logininfo = new DTLoginInfo();
$isloggedin = $lservice->ServerLogin($sesid, ‘23dashes’, ‘23dashes’, $logininfo);
if ($isloggedin == TRUE)
{
echo ‘logged in’;
}
else
{
echo ‘not logged in’;
}

foreach ($logininfo as $name => $value) {
echo “$name: $value”;
}

Hello,
Add to your login method the following line:

function ServerLogin($sesid, $login, $password, $logininfo)
  $___msg = new xmlrpcmsg("LoginService.ServerLogin");
  $___msg->addParam(new xmlrpcval($sesid, "string")); //<=====
  $___msg->addParam(new xmlrpcval($login, "string"));
  ................

Great! That fixed the login.
But now the Sum function in PHP is not working.

Apparently the interface builder is not creating PHP interface correctly.

ServerLogin was created by the interface builder.
The ServerLogin function is a member of the LoginService.

The Sum function is a member of the CoreService.
Here is the Sum function created by the interface builder…

class CoreService {
function CoreService($path, $server='', $port='', $method='') {
    $this->___server = new xmlrpc_client($path, $server, $port, $method);
}

function GetXmlRpcClient() {
    return $this->___server;
}
// Sum(A: Integer, B: Integer) {
function Sum($A, $B) {
    $___msg = new xmlrpcmsg("CoreService.Sum");
    $___msg->addParam(new xmlrpcval($A, "int"));
    $___msg->addParam(new xmlrpcval($B, "int"));
    $___res = $this->___server->send($___msg);
    if ($___res->faultCode()) AppServerLibraryHelpers::RaiseException($___res->faultString());
    return $___res->value()->scalarval();
}

Fatal error: Uncaught exception ‘Exception’ with message
’Not a string’ in D:\Ammps\www\AppServerLibrary_intf.inc:30
Stack trace:
0 D:\Ammps\www\AppServerLibrary_intf.inc(1595): AppServerLibraryHelpers::RaiseException(‘Not a string’)
1 D:\Ammps\www\gktest.php(19): CoreService->Sum(3, 5)
2 {main} thrown in D:\Ammps\www\AppServerLibrary_intf.inc on line 30


So I modify it like I did the Login function…

    // Sum(A: Integer, B: Integer) {
function Sum($sesid, $A, $B) {                          //<==== changed this
    $___msg = new xmlrpcmsg("CoreService.Sum");
    $___msg->addParam(new xmlrpcval($sesid, "string")); //<==== add this
    $___msg->addParam(new xmlrpcval($A, "int"));
    $___msg->addParam(new xmlrpcval($B, "int"));
    $___res = $this->___server->send($___msg);
    if ($___res->faultCode()) AppServerLibraryHelpers::RaiseException($___res->faultString());
    return $___res->value()->scalarval();
}

Now here is my php code to call the function Sum…

$htmlbr = chr(60).‘br’.chr(62);
$sesid = com_create_guid();
echo $sesid.$htmlbr;
$lservice = new LoginService(‘http://localhost:8099/xmlrpc’);
$logininfo = new DTLoginInfo();
$isloggedin = $lservice->ServerLogin($sesid, ‘23dashes’, ‘23dashes’, $logininfo);
if ($isloggedin == TRUE)
{
echo ‘logged in’.$htmlbr;
}
else
{
echo ‘not logged in’.$htmlbr;
}

$cservice = new CoreService(‘http://localhost:8099/xmlrpc’);
$sumresult = $cservice->Sum($sesid, 3, 5);
echo $sumresult;

And here is the output generated in the browser…

{D66D7300-D1CD-4EE9-BF3E-1CC301DC31F6}
logged in

Fatal error: Uncaught exception ‘Exception’ with message
’EROSessionNotFound: Session {D66D7300-D1CD-4EE9-BF3E-1CC301DC31F6} could not be found’ in D:\Ammps\www\AppServerLibrary_intf.inc:30
Stack trace:
0 D:\Ammps\www\AppServerLibrary_intf.inc(1596): AppServerLibraryHelpers::RaiseException(‘EROSessionNotFo…’)
1 D:\Ammps\www\gktest.php(19): CoreService->Sum(’{D66D7300-D1CD-…’, 3, 5)
2 {main} thrown in D:\Ammps\www\AppServerLibrary_intf.inc on line 30

Hello,
Can you provide delphi code of ServerLogin method?
You can also attach your testcase. We will check it.

Too much code to post here.
The Python code works great, so it does not appear to be an issue with
the RO Server code.
I can send you some code, but I need an email address to send it to.
We do not want our Delphi code to show up on this forum.

You can send it to support@remobjects.com