Page 1 of 4 123 ... LastLast
Results 1 to 10 of 32

Thread: Working with web services and SOAP in Lianja

  1. #1
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    7,163
    Blog Entries
    22

    Working with web services and SOAP in Lianja

    In Lianja Beta10 we have added an additional (optional) parameter to the GETURL( ) function to read a file from a remote web server and store its contents into a local file.

    Code:
    // perform a query against a remote server and return a chunk of JSON into a file
    filename = geturl("http://www.myserver.com/getsomepage.rsp?name=smith&month=10", 30, array(), "myfilename.json")
    if len(filename) = 0    
        // no data was returned
    endif
    We have also ddded a new function POSTURL( ) that operates in the same way as GETURL( ) but sends an HTTP POST request to the specified URI. By default the data is just sent as "text/plain" in the HTTP body but you can add custom headers to the "headers" associative array and POST SOAP requests and read the response from the remote server which is returned as a string of text. The last parameter can either be a filename or a character expression that will be sent as the POST body.

    Code:
    // send a soap request
    response = posturl("http://www.myserver.com/somewebservice.aspx", ;
                               30, ;
                               array("type" => "Content-Type: text/xml"), ;
                               "somefilename.xml")
    
    if len(response) = 0    
        // no data was returned
    endif 
    
    // submit a form
    response = posturl("http://www.myserver.com/someformsubmission.rsp", ;
                               30, ;                              
                               array("type" => "Content-Type: application/x-www-form-urlencoded"), ;
                               "name=barry&product=lianja")                                         
    if len(response) = 0    
        // no data was returned
    endif
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  2. #2
    Hi,

    I am trying to get an address from the free google service.
    I am passing in an address.

    filename = geturl("http://maps.googleapis.com/maps/api/geocode/xml?address=100 valentine street 08904&sensor=false", 30, array(), "myfilename.xml")
    myobject = xml_decode_file(filename, "GeocodeResponse", "Status")

    In my example, I am trying to get the status.
    I am sure it is simple. but I am missing it.


    This is a partial response that I copied from my browser.
    This XML file does not appear to have any style information associated with it. The document tree is shown below.
    <GeocodeResponse>
    <status>OK</status>
    <result>
    <type>street_address</type>
    <formatted_address>100 Valentine Street, Highland Park, NJ 08904, USA</formatted_address>
    <address_component>

    Thanks.

    Herb

  3. #3
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,842
    Hi Herb,

    This will get you the file:

    Code:
    oRequest = createObject("networkrequest")
    oRequest.getfile("http://maps.googleapis.com/maps/api/geocode/xml?address=100 valentine street 08904&sensor=false","myfilename.xml")
    and this will display the status:

    Code:
    myobject = xml_decode_file("myfilename.xml", "GeocodeResponse")
    ? myobject['status']
    I'm just looking into using the third parameter on xml_decode_file - I believe you should be able to specify 'status', but will check.

    Regards,

    Yvonne

  4. #4
    Thanks Yvonne,

    I had the option of getting the results as a json and that is working fine for me using geturl.
    Is one method preferred over the other?

    Meaning geturl vs networkrequest?

    Thanks.

    Herb

  5. #5
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,842
    Hi Herb,

    For larger/more complex amounts of data I would go with NetworkRequest.

    Regards,

    Yvonne

  6. #6
    Hi,

    I am using networkrequest for an HTTPS request.
    I am having some difficulty traversing the XML output.

    Here is the output of my file.
    Dynarray (refcnt=0)
    (
    [status] => OK
    [result] => <type>street_address</type> <formatted_address>100 Valentine Street, Highland Park, NJ 08904, USA</formatted_address> <address_component> <long_name>100</long_name> <short_name>100</short_name> <type>street_number</type> </address_component> <address_component> <long_name>Valentine Street</long_name> <short_name>Valentine St</short_name> <type>route</type> </address_component> <address_component> <long_name>Highland Park</long_name> <short_name>Highland Park</short_name> <type>locality</type> <type>political</type> </address_component> <address_component> <long_name>Middlesex</long_name> <short_name>Middlesex</short_name> <type>administrative_area_level_2</type> <type>political</type> </address_component> <address_component> <long_name>New Jersey</long_name> <short_name>NJ</short_name> <type>administrative_area_level_1</type> <type>political</type> </address_component> <address_component> <long_name>United States</long_name> <short_name>US</short_name> <type>country</type> <type>political</type> </address_component> <address_component> <long_name>08904</long_name> <short_name>08904</short_name> <type>postal_code</type> </address_component> <geometry> <location> <lat>40.4910198</lat> <lng>-74.4298371</lng> </location> <location_type>RANGE_INTERPOLATED</location_type> <viewport> <southwest> <lat>40.4896776</lat> <lng>-74.4311887</lng> </southwest> <northeast> <lat>40.4923755</lat> <lng>-74.4284908</lng> </northeast> </viewport> <bounds> <southwest> <lat>40.4910198</lat> <lng>-74.4298424</lng> </southwest> <northeast> <lat>40.4910333</lat> <lng>-74.4298371</lng> </northeast> </bounds> </geometry> )
    I can get status and result, but cant seem to figure out how to get beyond that point to my individual values under the result node.
    I have tried to reference the values using different array techniques - dot notation and direct names ie ['long_name']

    It's probably simple, but I cant figure it out.
    Thanks.
    Herb

  7. #7
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    7,163
    Blog Entries
    22
    Hi Herb,

    I am intending to add two new classes in v1.1 "xmlreader" and "xmlwriter" but at the moment the xml_decode() function won't handle a structure it does not understand.

    Can you let me see the complete xml that is returned. Looking at what you have posted its not properly formed as an xml tree. Just looks like a stream of xml tags with no proper document structure.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  8. #8
    Hi,

    Does networkrequest expect a certain file format?
    Meaning, can I get back a json data set or an XML data set?

    Thanks.

    Herb

  9. #9
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,842
    Hi Herb,

    I don't think the type of file matters to NetworkRequest.getfile() - you just need to handle the file appropriately once you've 'got' it. You could use FOPEN(), FGETS() etc. for customized handling if required, e.g.

    Code:
    oRequest = createObject("networkrequest")
    oRequest.getfile("http://maps.googleapis.com/maps/api/geocode/xml?address=100 valentine street 08904&sensor=false","myfilename.xml")
    fd = fopen("myfilename.xml")
    do while not feof(fd)
    	m_string = fgets(fd)
    	if at("<lat>",m_string) > 0
    		? strextract(m_string,"<lat>","</lat>")
    	endif
    enddo
    fclose(fd)
    Regards,

    Yvonne

  10. #10
    Thanks Yvonne,

    I must admit that I was not aware of the strextract function.
    That is very helpful.

    Herb

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us