Use of XML-RPC methods



I am trying to use libsoup's XML-RPC client methods to get data from a remote application .. using genie (or vala). Using the code

[indent=4]
/* Build with "valac --thread --pkg libsoup-2.4 yourfile.gs */
uses
    Soup
    Gee
struct LocQty
    quantity : double
    loccode : string

	
init
    var session = new Soup.SessionAsync ()
    ItemCode:string = "DVD-TOPGUN"
    UserName:string = "admin"
    Password:string = "weberp"

var message = Soup.xmlrpc_request_new ("http://localhost/webERP/api/api_xml-rpc.php";, "weberp.xmlrpc_GetStockBalance", typeof(string),ItemCode, typeof(string), UserName, typeof(string), Password)

    session.send_message(message)

    ResponseData:string = message.response_body.flatten().data
    MessageLength : int = (int) message.response_body.length

    try
xmlrpc_parse_method_response (ResponseData, MessageLength, typeof(int))
        print("Stock of %s = %s",ItemCode, ResponseData)
    except
        print("Could not get webERP API location stock over XML-RPC.")


    print ("message length = %d",MessageLength)

I get a nice response from the web-server :

Stock of DVD-TOPGUN = <?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value><array>
<data>
<value><int>0</int></value>
<value><array>
<data>
<value><struct>
<member><name>quantity</name>
<value><string>-1</string></value>
</member>
<member><name>loccode</name>
<value><string>MEL</string></value>
</member>
</struct></value>
<value><struct>
<member><name>quantity</name>
<value><string>0</string></value>
</member>
<member><name>loccode</name>
<value><string>TOR</string></value>
</member>
</struct></value>
</data>
</array></value>
</data>
</array></value>
</param>
</params>
</methodResponse>


I am figuring that the xmlrpc_extract_method_response is the method to parse the returned xml into an array of structs?? But I can't figure out how to use it and can find no examples on the net...

Would appreciate any ideas?

Phil


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]