xml-rpc webserver

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ward Germonpré

    xml-rpc webserver

    Been banging my head on this all day, so here's the stoopid question:

    Do we *really need* the xml-rpc extension to create a xmlrpc
    webservice ?

    I'm getting the impression that we're supposed to generate the XML by hand.
    That's why PHP 5.1.2 has DOM methods as well as an xmlwriter class.

    And invoking the webserver "function/class" can be done by general PHP code
    as well, no need for *registering the method with the server* ?

    Many webauthors urge us to precede any xml output with : header('Content-
    Type: text/xml');

    So if we have to do all that ourselves, what work does the xml-rpc
    extension actually do ?




    Below is my first webservice effort, using POST.

    The js-client sends "Kilroy", and the webservice appends ' was here'.
    I'm receiving an XML object all right, but it appears empty.

    Any help appreciated...

    regards
    Ward



    //save this as server.php
    <?php
    function stick($method, $param) {
    return ("$param was here !");
    }
    $server = xmlrpc_server_c reate();
    $rawpost=$HTTP_ RAW_POST_DATA;
    xmlrpc_server_r egister_method( $server, "glue", "stick");
    $xmlresponse= xmlrpc_server_c all_method($ser ver, $rawpost, '');
    header('Content-Type: text/xml');
    echo $xmlresponse;
    ?>





    //save this as client.html (most of the code courtesy of PPK)
    <html>
    <script>
    var XMLHttpFactorie s = [
    function () {return new XMLHttpRequest( )},
    function () {return new ActiveXObject(" Msxml2.XMLHTTP" )},
    function () {return new ActiveXObject(" Msxml3.XMLHTTP" )},
    function () {return new ActiveXObject(" Microsoft.XMLHT TP")},
    ];

    function dspobjprop(obj) {
    var props="";
    for (var prop in obj) {props+=prop+'= '+obj[prop]+'\n';}
    alert (props);
    }
    function createXMLHTTPOb ject() {
    var xmlhttp = false;
    for (var i=0;i<XMLHttpFa ctories.length; i++)
    {
    try {
    xmlhttp = XMLHttpFactorie s[i]();
    }
    catch (e) {
    continue;
    }
    break;
    }
    return xmlhttp;
    }

    function sendRequest(url ,callback, postData) {
    var req = createXMLHTTPOb ject();
    if (!req) return;
    var method = (postData) ? "POST" : "GET";
    req.open(method ,url,true);
    req.setRequestH eader('User-Agent','XMLHTTP/1.0');
    if (postData)
    req.setRequestH eader('Content-type','applicat ion/x-www-form-
    urlencoded');
    req.onreadystat echange = function () {
    if (req.readyState != 4) return;
    if (req.status != 200 && req.status != 304) {

    alert('HTTP error ' + req.status);
    return;
    }
    callback(req);
    }
    if (req.readyState == 4) return;
    req.send(data);
    }

    function handleResponse( req){
    var returnXML=req.r esponseXML;
    alert(returnXML );
    document.innerH TML=returnXML;
    alert(returnXML .getElementsByT agName('rawpost ')
    [0].firstChild.nod eValue);
    }


    var data="Kilroy";
    sendRequest('se rver.php', handleResponse, 'POST');


    </script>
    </html>


Working...