11.07.2015 Views

in PowerBuilder - sys-con.com's archive of magazines - SYS-CON ...

in PowerBuilder - sys-con.com's archive of magazines - SYS-CON ...

in PowerBuilder - sys-con.com's archive of magazines - SYS-CON ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

We call PostURL with our additional parameters (portbe<strong>in</strong>g//The response from the web service will be sent to the//InternetData method <strong>in</strong> the lnvo_<strong>in</strong>ternet_result object//and execute the code there (popp<strong>in</strong>g up a MessageBox)li_retval = l<strong>in</strong>et_base.PostURL(ls_url, &lblb_args, &ls_headers, &ll_port, &lnvo_<strong>in</strong>ternet_result)//Clean updestroy l<strong>in</strong>et_basedestroy lnvo_<strong>in</strong>ternet_resultList<strong>in</strong>g 3//First download and <strong>in</strong>stall the latest XmlHttp package//(this l<strong>in</strong>k goes to the one listed <strong>in</strong>//the <strong>con</strong>nectToNewObject call - “Msxml2.XMLHTTP.4.0”//http://www.micros<strong>of</strong>t.com/downloads/details.aspx?familyid=3144b72b-b4f2-46da-b4b6-c5d7485f2b42&displaylang=en#filelist//XmlHttp object method summary//http://msdn.micros<strong>of</strong>t.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmmscxmldommethods.aspStr<strong>in</strong>g ls_get_url, ls_post_urlStr<strong>in</strong>g ls_args, ls_responseStr<strong>in</strong>g ls_response_text, ls_status_textlong ll_status_codeOleObject loo_xmlhttpls_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 <strong>in</strong>stance <strong>of</strong> our COM objectloo_xmlhttp = CREATE oleobjectloo_xmlhttp.ConnectToNewObject(“Msxml2.XMLHTTP.4.0”)//First lets do a GET requestloo_xmlhttp.open (“GET”,ls_get_url + ls_args, false)loo_xmlhttp.send()//Get our responsels_status_text = loo_xmlhttp.StatusTextll_status_code = loo_xmlhttp.Status//Check HTTP Response code for errors//http://kbs.cs.tu-berl<strong>in</strong>.de/~jutta/ht/responses.htmlif ll_status_code >= 300 thenMessageBox(“GET Request Failed”, ls_response_text)else//Get the response we received from the web serverls_response_text = loo_xmlhttp.ResponseTextMessageBox(“GET Request Succeeded”, ls_response_text)end if//Lets do a POST now, notice now we will pass a Str<strong>in</strong>g//<strong>in</strong> the send() call that <strong>con</strong>ta<strong>in</strong>s the arguments <strong>in</strong> 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 responsels_status_text = loo_xmlhttp.StatusTextll_status_code = loo_xmlhttp.Status//Check HTTP Response code for errors//http://kbs.cs.tu-berl<strong>in</strong>.de/~jutta/ht/responses.htmlif ll_status_code >= 300 thenMessageBox(“POST Request Failed”, ls_response_text)else//Get the response we received from the web serverls_response_text = loo_xmlhttp.ResponseTextMessageBox(“POST Request Succeeded”,ls_response_text)end if//Done so cleanuploo_xmlhttp.Dis<strong>con</strong>nectObject()catch (RuntimeError rte)MessageBox(“Error”, “RuntimeError - “+ rte.getMessage())end tryList<strong>in</strong>g 4long ll_retval, ll_rowcount, iStr<strong>in</strong>g ls_accesskeyid, ls_subscriptionid, ls_associatetagStr<strong>in</strong>g ls_xmlescap<strong>in</strong>g, ls_validate, ls_responseSoapConnection lsoap_<strong>con</strong>nawsecommerceserviceport lws_amazontns__itemsearchrequest lstr_searchrequesttns__itemsearchrequest lstr_searchrequestarray[]tns__operationrequest lstr_operationrequesttns__items lstr_itemsls_accesskeyid = “[YourAccessKey]”ls_subscriptionid = “”ls_associatetag = “”ls_xmlescap<strong>in</strong>g = “S<strong>in</strong>gle”ls_validate = “True”lstr_searchrequest.search<strong>in</strong>dex = “Music”lstr_searchrequest.keywords = “Butch Walker”lws_amazon = create awsecommerceserviceport//Instantiate SOAP <strong>con</strong>nectionlsoap_<strong>con</strong>n = create SoapConnection// Set trace file to record soap <strong>in</strong>terchange data,ll_retval = lsoap_<strong>con</strong>n.SetOptions(‘SoapLog=’ + &‘“C:\mySoapLog.log”’)ll_retval = lsoap_<strong>con</strong>n.CreateInstance(lws_amazon, &“awsecommerceserviceport”)if ll_retval 0 thenas_errmsg = “Unable to create proxy. “ + &“Error Code: “ + Str<strong>in</strong>g(ll_retval)else// make call to web servicetrylstr_items = lws_amazon.itemsearch(ls_subscriptionid, &ls_accesskeyid, &ls_associatetag, &ls_xmlescap<strong>in</strong>g, &ls_validate, &lstr_searchrequest, &lstr_searchrequestarray, &lstr_operationrequest)ll_rowcount = lstr_items.totalresults//Iterate our response for <strong>in</strong>formationfor i=1 to ll_rowcountls_response = ls_response + &“ASIN: “ + &lstr_items.item[i].as<strong>in</strong> + &“ Artist: “ + &lstr_items.item[i].itemattributes.artist[1] + &“ Title: “ + &lstr_items.item[i].itemattributes.title + “~r~n”nextMessageBox(“Web Service Response”,ls_response)catch ( SoapException e )MessageBox(“Soap Exception”, &“Cannot <strong>in</strong>voke Web Service: “ +e.text)end tryend if//Cleanupif isValid(lsoap_<strong>con</strong>n) thendestroy lsoap_<strong>con</strong>nend ifwww.<strong>SYS</strong>-<strong>CON</strong>.COM/pbdj/PBDJ volume12 issue1133

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!