Listing 1
nvo_internet_result lnvo_internet_result
inet linet_base
integer li_retval
String ls_url, ls_args
//Initialize InternetResult object and
//Get Internet service reference
lnvo_internet_result = create nvo_internet_result
li_retval = GetContextService("Internet", linet_base)
//Web Service URL, note the question mark included
//on the end. Don't forget this
ls_url="http://webservices.amazon.com/onca/xml?"
//Argument list of name/value pairs in the format
//=&
ls_args="Service=AWSECommerceService&" + &
"AWSAccessKeyId=[YourAccessKey]&" + &
"Operation=ItemSearch&" + &
"SearchIndex=Music&" + &
"Keywords=Butch Walker"
//Concatenate URL with Arguments and call GetURL method.
//The response from the web service will be sent to the
//InternetData method in the lnvo_internet_result object
//and execute the code there (popping up a MessageBox)
li_retval = linet_base.GetURL(ls_url + ls_args, & lnvo_internet_result)
//Clean up
destroy linet_base
destroy lnvo_internet_result
Listing 2
nvo_internet_result lnvo_internet_result
inet linet_base
integer li_retval
long ll_content_length, long ll_port
String ls_url, ls_args, ls_headers
blob lblb_args
//Initialize InternetResult object and
//Get Internet service reference
lnvo_internet_result = create nvo_internet_result
li_retval = GetContextService("Internet", linet_base)
//Web Service URL, note the question mark included
//on the end. Don't forget this
ls_url="http://webservices.amazon.com/onca/xml?"
//Server Port Number, typically 80 or 0 for default
//Note putting 443 here does not give you HTTPS
ll_port = 80
//Argument list of name/value pairs in the format
//=&
ls_args="Service=AWSECommerceService&" + &
"AWSAccessKeyId=[YourAccessKey]&" + &
"Operation=ItemSearch&" + &
"SearchIndex=Music&" + &
"Keywords=Butch Walker"
//For PostURL we will convert our argument list
//from a string to a blob and get the length of
//our resulting blob
lblb_args = blob(ls_args)
ll_content_length = Len(lblb_args)
//For PostURL we also have to set two HTML headers
//Content-Length and Content-Type separated by two
//newline characters
ls_headers = "Content-Length: " + &
String(ll_content_length) + "~n~n" + &
"Content-Type: " + &
"application/x-www-form-urlencoded"
//We call PostURL with our additional parameters (port being
//The response from the web service will be sent to the
//InternetData method in the lnvo_internet_result object
//and execute the code there (popping up a MessageBox)
li_retval = linet_base.PostURL(ls_url, &
lblb_args, &
ls_headers, &
ll_port, &
lnvo_internet_result)
//Clean up
destroy linet_base
destroy lnvo_internet_result
Listing 3
//First download and install the latest XmlHttp package
//(this link goes to the one listed in
//the connectToNewObject call - "Msxml2.XMLHTTP.4.0"
//http://www.microsoft.com/downloads/details.aspx?
familyid=3144b72b-b4f2-46da-b4b6-c5d7485f2b42&display
lang=en#filelist
//XmlHttp object method summary
//http://msdn.microsoft.com/library/default.asp?url=/library/
en-us/xmlsdk/html/xmmscxmldommethods.asp
String ls_get_url, ls_post_url
String ls_args, ls_response
String ls_response_text, ls_status_text
long ll_status_code
OleObject loo_xmlhttp
ls_get_url = "http://webservices.amazon.com/onca/xml?"
ls_post_url = "http://webservices.amazon.com/onca/xml"
ls_args = "Service=AWSECommerceService&" + &
"AWSAccessKeyId=[YourAccessKey]&" + &
"Operation=ItemSearch&" + &
"SearchIndex=Music&" + &
"Keywords=Butch Walker"
try
//Create an instance of our COM object
loo_xmlhttp = CREATE oleobject
loo_xmlhttp.ConnectToNewObject("Msxml2.XMLHTTP.4.0")
//First lets do a GET request
loo_xmlhttp.open ("GET",ls_get_url + ls_args, false)
loo_xmlhttp.send()
//Get our response
ls_status_text = loo_xmlhttp.StatusText
ll_status_code = loo_xmlhttp.Status
//Check HTTP Response code for errors
//http://kbs.cs.tu-berlin.de/~jutta/ht/responses.html
if ll_status_code >= 300 then
MessageBox("GET Request Failed", ls_response_text)
else
//Get the response we received from the web server
ls_response_text = loo_xmlhttp.ResponseText
MessageBox("GET Request Succeeded", ls_response_text)
end if
//Lets do a POST now, notice now we will pass a String
//in the send() call that contains the arguments in the
//format name1=value1&name2=value2&...
loo_xmlhttp.open ("POST",ls_post_url, false)
loo_xmlhttp.setRequestHeader("Content-Type", &
"application/x-www-form-urlencoded")
loo_xmlhttp.send(ls_args)
//Get our response
ls_status_text = loo_xmlhttp.StatusText
ll_status_code = loo_xmlhttp.Status
//Check HTTP Response code for errors
//http://kbs.cs.tu-berlin.de/~jutta/ht/responses.html
if ll_status_code >= 300 then
MessageBox("POST Request Failed", ls_response_text)
else
//Get the response we received from the web server
ls_response_text = loo_xmlhttp.ResponseText
MessageBox("POST Request Succeeded", ls_response_text)
end if
//Done so cleanup
loo_xmlhttp.DisconnectObject()
catch (RuntimeError rte)
MessageBox("Error", "RuntimeError - " + rte.getMessage())
end try
Listing 4
long ll_retval, ll_rowcount, i
String ls_accesskeyid, ls_subscriptionid, ls_associatetag
String ls_xmlescaping, ls_validate, ls_response
SoapConnection lsoap_conn
awsecommerceserviceport lws_amazon
tns__itemsearchrequest lstr_searchrequest
tns__itemsearchrequest lstr_searchrequestarray[]
tns__operationrequest lstr_operationrequest
tns__items lstr_items
ls_accesskeyid = "[YourAccessKey]"
ls_subscriptionid = ""
ls_associatetag = ""
ls_xmlescaping = "Single"
ls_validate = "True"
lstr_searchrequest.searchindex = "Music"
lstr_searchrequest.keywords = "Butch Walker"
lws_amazon = create awsecommerceserviceport
//Instantiate SOAP connection
lsoap_conn = create SoapConnection
// Set trace file to record soap interchange data,
ll_retval = lsoap_conn.SetOptions('SoapLog=' + &
'"C:\mySoapLog.log"')
ll_retval = lsoap_conn.CreateInstance(lws_amazon, &
"awsecommerceserviceport")
if ll_retval <> 0 then
as_errmsg = "Unable to create proxy. " + &
"Error Code: " + String(ll_retval)
else
// make call to web service
try
lstr_items = lws_amazon.itemsearch
(ls_subscriptionid, &
ls_accesskeyid, &
ls_associatetag, &
ls_xmlescaping, &
ls_validate, &
lstr_searchrequest, &
lstr_searchrequestarray, &
lstr_operationrequest)
ll_rowcount = lstr_items.totalresults
//Iterate our response for information
for i=1 to ll_rowcount
ls_response = ls_response + &
"ASIN: " + &
lstr_items.item[i].asin + &
" Artist: " + &
lstr_items.item[i].itemattributes.
artist[1] + &
" Title: " + &
lstr_items.item[i].itemattributes.
title + "~r~n"
next
MessageBox("Web Service Response", ls_response)
catch ( SoapException e )
MessageBox("Soap Exception", &
"Cannot invoke Web Service: " + e.text)
end try
end if
//Cleanup
if isValid(lsoap_conn) then
destroy lsoap_conn
end if
http://pbdj.sys-con.com/read/170853.htm