1. Euphoria SOAP client

I would like to use euphoria to interact with web site which uses a SOAP API. To do this I need to use some kind of transport protocol, which apparently is usually HTTP (GET and POST). My knowledge of networking is basically zero, but I assume I need to use some kind of socket library to do this? I'm using eu 3.1.1 on Linux. If anyone has any experience of using SOAP with euphoria, any advice would be much appreciated!

Some basic info on SOAP: http://www.soapuser.com/basics1.html

Thanks in advance!

new topic     » topic index » view message » categorize

2. Re: Euphoria SOAP client

Jules said...

I would like to use euphoria to interact with web site which uses a SOAP API.

I recently wrote code that lets me do ecommerce transactions with PayPal, during which you have to send form POST data back to them. I'm using wget for that and it works very well, though I'm sure there's a library available that would let me skip the step of saving the result into a file and then reading it into a variable. Other than that, I'm satisfied with using wget for this.

I hope in the future to use an integrated Euphoria library that does not require an external program like wget.

Here's a little snippet to show how simple can be interface wise:

if SANDBOX then -- when doing transaction testing 
	confirm = "cmd=_notify-synch&tx=" & pptx & "&at=" & my_code 
	pp_site = "https://www.sandbox.paypal.com/cgi-bin/webscr" 
else -- when doing live transactions 
	confirm = "cmd=_notify-synch&tx=" & pptx & "&at=" & my_code 
	pp_site = "https://www.paypal.com/cgi-bin/webscr" 
end if 
 
result = getURL( pp_site, {"--post-data \"" & confirm & "\"","--no-check-certificate"}) 

The --post-data parameter tells wget to send it as a form POST instead of as GET. result ends up containing the text of the URL grabbed (in the case above, the URL stored in pp_site).

new topic     » goto parent     » topic index » view message » categorize

3. Re: Euphoria SOAP client

euphoric said...
Jules said...

I would like to use euphoria to interact with web site which uses a SOAP API.

I recently wrote code that lets me do ecommerce transactions with PayPal, during which you have to send form POST data back to them. I'm using wget for that and it works very well, though I'm sure there's a library available that would let me skip the step of saving the result into a file and then reading it into a variable.

EuNet is a socket library for 3.1.1, included in the 4.0 standard library as socket.e. I don't have a POST example on hand, but some other users have handled POST successfully with the library.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Euphoria SOAP client

m_sabal said...

EuNet is a socket library for 3.1.1, included in the 4.0 standard library as socket.e. I don't have a POST example on hand, but some other users have handled POST successfully with the library.

Yeah, I just haven't gotten around to using it. sad

Soon, I hope! smile

new topic     » goto parent     » topic index » view message » categorize

5. Re: Euphoria SOAP client

Thanks guys for the feedback. I had a look at eunet and it seems that support for POST was added recently, now I just have to figure out how to use it, there aren't any examples yet in the 4.0 docs.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Euphoria SOAP client

If someone could show me an example of using POST with socket.e, I'd be eternally grateful. I'm going nowhere fast. :(

new topic     » goto parent     » topic index » view message » categorize

7. Re: Euphoria SOAP client

Jules said...

If someone could show me an example of using POST with socket.e, I'd be eternally grateful. I'm going nowhere fast. :(

I think that post is used for CGI.
So go to the archive of user contribution and do
a search on CGI and you will see about 20 programs.
One of those probably has a demo that uses POST.

new topic     » goto parent     » topic index » view message » categorize

8. Re: Euphoria SOAP client

Keep in mind that POST and GET are two different ways of doing the same thing. I mention this because it makes it easier to understand the way in which you interface with a CGI server, which the SOAP server is.

To take an example, go to this page of mine:

http://www.wazu.jp/hosting/pricing.exu

Fill in a few forms, tick a few boxes, and hit 'Price This Plan'.

You have just sent data to my server using POST.

Now enter:

http://www.wazu.jp/hosting/pricing.exu?&email_count=7&disk_count=100&transfer_count=33&sql_count=3&multi_count=1&billing_currency=JPY&price_me=Price+or+Re-Price+This+Plan&domain_name=+&given_name=+&family_name=+&country=+&email=+&email_check=+

in the address bar.

You have just sent data to my server using a GET.

Note what's in the url and what's displayed on the page.

When large amounts of data are involved, POST is more appropriate. But you can see that essentially the same data are sent in each case.

For SOAP, you have to generate your XML, and send it to the CGI interface, using POST.

I use a Euphoria implementation of libcurl, and have one program that does webscraping, using POST, daily.

Here is an extract of the code, to show you how easy it is. The program is a few thousand lines long, but I've just extracted the relevant libcurl statements.

include C:\EUPHORIA\INCLUDE\euLibCurl.ew 
 
atom curl_handle 
atom errp -- curl error 
errp = allocate(CURL_ERROR_SIZE) 
 
 
--**************************************************************** 
--**********           function get_url           **************** 
--**************************************************************** 
function get_url(sequence url, object form_data) 
-- form_data can be NO_FORMS 
-- returns HTML page or error code 
object buffer, buffer2 
if connexion_mode = SOCKS then 
	void = curl_easy_setopt(curl_handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5) 
	void = curl_easy_setopt(curl_handle, CURLOPT_PROXY, "127.0.0.1:4567") 
	void = curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, "C:\\EUPHORIA\\accounts\\SOCKS_cookies") 
	void = curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, "C:\\EUPHORIA\\accounts\\SOCKS_cookies") 
	void = curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)") 
elsif connexion_mode = Proxy then 
	void = curl_easy_setopt(curl_handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP) 
	void = curl_easy_setopt(curl_handle, CURLOPT_PROXY, "192.168.0.1:4480") 
	void = curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, "C:\\EUPHORIA\\accounts\\Proxy_cookies") 
	void = curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, "C:\\EUPHORIA\\accounts\\Proxy_cookies") 
	void = curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4") 
else -- Direct 
	void = curl_easy_setopt(curl_handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP) 
	void = curl_easy_setopt(curl_handle, CURLOPT_PROXY, "") 
	void = curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, "C:\\EUPHORIA\\accounts\\Direct_cookies") 
	void = curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, "C:\\EUPHORIA\\accounts\\Direct_cookies") 
	void = curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Opera/9.21 (Windows NT 5.1; U; en)") 
end if 
 
void = curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0) 
-- CURLOPT_CAINFO and CURLOPT_CAPATH would be used to point to certificates, 
-- but the line above says not to verify the SSL certificate 
 
if sequence (form_data) then 
	void = curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, form_data) 
else 
	void = curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1) 
end if 
 
void = curl_easy_setopt(curl_handle, CURLOPT_URL, url) 
if sequence(form_data) then 
	showMessage(sprintf("Downloading file %s : %s",{url,form_data})) 
else 
	showMessage(sprintf("Downloading file %s",{url})) 
end if 
buffer = curl_easy_perform_ex(curl_handle) 
if atom(buffer) then 
	showMessage(sprintf("Error '%s' downloading file", {peek_sequence(errp, CURL_ERROR_SIZE) } ) ) 
end if 
return buffer 
end function 
-------------------------------------------------------------------------------- 
 
curl_easy_cleanup(curl_handle) 
curl_global_cleanup() 
free(errp) 
 
if  curl_global_init(CURL_GLOBAL_ALL) != 0 then 
	warnErr("Could not initialise libCurl\n\nContinue?") 
end if 
 
curl_handle = curl_easy_init() 
void = curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, errp) 
void = curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1) 
new topic     » goto parent     » topic index » view message » categorize

9. Re: Euphoria SOAP client

Hi Bellthorpe, thanks for posting this. I didn't bother looking at eulibcurl, because I'm running linux. I think I can solve my problem by running some Perl code from euphoria, which has good support for SOAP. It means I'll have to learn Perl, but I think it's going to be faster than figuring out how to do everything in eu. Shame really.

new topic     » goto parent     » topic index » view message » categorize

10. Re: Euphoria SOAP client

No problem. I should mention that Eulibcurl is available for Linux.

Perl does have some available routines, but rather than learn a new language, I think I'd persevere with Euphoria.

In any case, I expect I'll have to write some SOAP stuff towards the end of the year, so it would be good if you kept this forum up to date with your progress.

There are of course routines for generating / parsing XML, such as Eebax.

Craig

new topic     » goto parent     » topic index » view message » categorize

11. Re: Euphoria SOAP client

CraigWelch said...

No problem. I should mention that Eulibcurl is available for Linux.

It is? I couldn't see it anywhere in the archive...

By the way, is it possible to edit/modify a posted after it has been posted? in my previous post it sounded as though I was saying that eu has good support for SOAP, which is not what I meant.

I would love to get this written in euphoria, but I find the networking code quite intimidating - I feel like I'm just groping around in the dark. Not sure whether it would take longer to learn Perl from scratch, or figure out how to use Eu. The attraction of using Perl is that all the modules are in place, and all the low-level stuff is hidden from the user.

I even asked Rob if he could do this for me, but he replied that it was outside his area of expertise, which made me feel a bit better. smile

new topic     » goto parent     » topic index » view message » categorize

12. Re: Euphoria SOAP client

Jules,

I tried to email you the package, to pipex and toucansurf, but both bounced. You can email me from the url I provided earlier in this thread if you'd like me to send it to you.

It's Ray Smith's package, enhanced by Julio C. Galaret Viera, who uses it on Linux.

From the code:

if platform() = WIN32 then 
    libcURL = link_dll("C:\\EUPHORIA\\INCLUDE\\libcurl.dll") 
elsif platform() = LINUX or platform() = FREEBSD then 
    libcURL = link_dll("libcurl.so") 
end if 

Most Linux distos have libcurl installed. Try slocate libcurl and/or man libcurl. Current downloads of the package are here.

In any case, even wget supports POST operations. My preference is libcurl.

I'm not trying to talk you out of using Perl, just suggesting that the CGI client interface in Euphoria is not all that difficult. I would suggest that you have three tasks ahead of you:

  1. Use a program such as eulibcurl to prove that you can fetch data from a CGI enabled host using POST [1]
  2. Use a program such as eebax to learn how to generate and parse XML
  3. Tie them together to make your SOAP connexion.

[1] I'm happy to give you server space for a while if you want to experiment with both sides of the CGI interface.

Craig

new topic     » goto parent     » topic index » view message » categorize

13. Re: Euphoria SOAP client

And if you're messing around with XML, I recommend you get a copy of the XmlPad editor

new topic     » goto parent     » topic index » view message » categorize

14. Re: Euphoria SOAP client

Thanks Craig. I'll email you. For anyone interested in testing SOAP (or REST), there is some handy software here: http://www.soapui.org/

new topic     » goto parent     » topic index » view message » categorize

15. Re: Euphoria SOAP client

Update:

To enable the SOAP request/response mechanism to work over HTTP, one HTTP header needs to be changed and one added.

The default header of "Content-Type: text/html" needs to change to "Content-Type: text/xml"

For this implementation a header "SOAPaction: xxxxx" was required, where 'xxxxx' might be 'login' or similar.

There is a constant, CURLOPT_HTTPHEADER, to pass to the function curl_easy_setopt. CURLOPT_HTTPHEADER had to be added to the list of constants. But curl_easy_setopt still couldn't use that constant correctly, as the paramater passed to the function needs to be a pointer to a linked list of headers to set.

This list is created with two more curl functions, curl_slist_append() and curl_slist_free_all(). I wrote function calls to those, and all was well.

Anyone who would like this revised eulibcURL.ew file is welcome to a copy.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu