Good source to read about making SOAP calls?

Anyone here know a tutorial (or care to write one) about making soap calls with Applescript in Mac OS X? Being a newbie with applescripting, the possibilities are tantalizing and many in xmethods.net. There seem to be lots of examples around, but not much explanation.

If it’s a simple matter, maybe explaining it would be simple, too.

Thanks!

John

Hi,

Here’s the developer documents on this:

http://developer.apple.com/documentation/AppleScript/Conceptual/soapXMLRPC/chapter2/chapter_2_section_3.html

There is a pdf on this somewhere.

gl,

The Apple Developer Connection’s SOAP scripting examples are thorough, but a bit out of date, of course. I realize that the web services themselves come and go. My problem is figuring out the various parameter values to pass to them in the script. When you use a service’s Try It feature, there is some code generated that seems to contain part of what I’m looking for:

method name
method namespace uri
method parameters
SOAPAction

Any ideas?

Hi jgthomas,

I had the same hurdles. What I did was start from examples and match the parameters from the scripts with what is on the website.

Here’s one example I ended up with:

set c1 to “united states”
set c2 to “united states”
set countryList to {“euro”, “united kingdom”, “japan”, “australia”, “switzerland”, “canada”}
set mn to “getRate”
set mnsurl to “urn:xmethods-CurrencyExchange”
set exch_rates to {}
try
with timeout of 20 seconds
repeat with c2 in countryList
tell application “http://services.xmethods.net:9090/soap/servlet
set theResult to ¬
call soap {method name:mn, parameters:{country1:c1, country2:c2}, method namespace uri:mnsurl}
end tell
set end of exch_rates to {(contents of c2), (theResult as number)}
end repeat
end timeout
on error
say “error or no response from exchange rate server.”
end try
return exch_rates

Go to xmethods:

http://www.xmethods.net/

and click the “currency exchange rates” link at the bottom of the page. Scroll down on the next page and you’ll see “detailed description”. You can match whats on that page with the values in the above script. I can’t remember why I added “servlet” to the end of the url, but I think it didn’t work without it before. Now it works without it.

gl,

OK. That was VERY instructive. A couple comments and a couple questions:

  1. So, method_name is also known as “ns1” around xmethods.net. (That’s a ‘one’ on the end, not an ‘el,’, right?)

  2. Method_namespace is also known as “xmlns,” right?

  3. How did you know to leave out the SOAP_action part all together?

  4. I couldn’t find your SOAP_app URL of http://services.xmethods.net:9090/soap/servlet anywhere among the ‘detailed description’…where did you get that from?

Thank you very much for your time and responses!

  1. Yes
  2. Yes
  3. No SOAPAction is listed
  4. The url is listed about at the top of the page under url.

I found a better way. At the top of the link page, there is a link “View RPC Profile”. If you hit that link there is a table of the values which has these values:

Method Name
getRate

Endpoint URL
http://services.xmethods.net:80/soap

SOAPAction

Method Namespace URI
urn:xmethods-CurrencyExchange

Input Parameters

country1
string

country2
string

Output Parameters

Result
float

Here’s the table values for BabelFish:

Method Name
BabelFish

Endpoint URL
http://services.xmethods.net:80/perl/soaplite.cgi

SOAPAction
urn:xmethodsBabelFish#BabelFish

Method Namespace URI
urn:xmethodsBabelFish

Input Parameters

translationmode
string

sourcedata
string

Output Parameters

return
string

Note that the SOAPAction is listed in this table and is used in the following script:

property SOAP_app : “http://services.xmethods.net:80/perl/soaplite.cgi
property method_name : “BabelFish”
property method_namespace_URI : “urn:xmethodsBabelFish”
property SOAP_action : “urn:xmethodsBabelFish#BabelFish”
property English_to_French : “en_fr”
property English_to_Spanish : “en_es”
property translation_mode : English_to_Spanish
– SOAP translation handler ------------------------------
on SOAP_call(SOAP_app, method_name, ¬
method_namespace_URI, method_parameters, SOAP_action)
try
using terms from application “http://www.apple.com/placebo
tell application SOAP_app
set this_result to call soap ¬
{method name:method_name ¬
, method namespace uri:method_namespace_URI ¬
, parameters:method_parameters ¬
, SOAPAction:SOAP_action}
end tell
end using terms from
return {true, this_result}
on error error_message
return {false, error_message}
end try
end SOAP_call

set this_text to “I love you.”
set the method_parameters to {translationmode:translation_mode, sourcedata:this_text}
copy my SOAP_call(SOAP_app, method_name, ¬
method_namespace_URI, method_parameters, SOAP_action) ¬
to {call_indicator, call_result}
{call_indicator, call_result}

The above script was from the pdf I think. The page at xmethods is there, but I think they removed the link. I got it through a search. It says that it’s being discontinued from AltaVista.

http://www.xmethods.com/ve2/ViewListing.po?serviceid=14

Remember, you get to the page with the table from the link “View RPC profile”

gl,

Hi jgthomas,

I just made this script using the fortune webservice gotten from xmethods:

– get topic
set SOAP_app to “http://www.doughughes.net/WebServices/fortune/fortune.cfc
set method_name to “getTopicsList”
set method_namespace_URI to “http://fortune.WebServices
–method_parameters - none
–SOAP_action - none
using terms from application “http://www.apple.com/placebo
tell application SOAP_app
set this_result to call soap {method name:method_name ¬
, method namespace uri:method_namespace_URI}
end tell
end using terms from
set topics_list to (words of this_result)
repeat
set the_topic to ¬
(choose from list topics_list with prompt “Select a topic for your fortune:”) as string
– get fortune
set method_name to “getFortune”
set method_parameters to {topics:the_topic, minLength:5.0, maxLength:50.0}
–SOAP_action - “none”
using terms from application “http://www.apple.com/placebo
try
tell application SOAP_app
set this_result to call soap {method name:method_name ¬
, method namespace uri:method_namespace_URI ¬
, parameters:method_parameters}
end tell
exit repeat
on error
say “Choose a new topic.”
end try
end using terms from
end repeat
display dialog this_result

gl,

I see the light! Thanks, kel.

John

I wanted to use the GetQuickQuote of cdyne’s PowerQuote web service because it handles mutual funds. I would like to write an AppleScript incorporating the service that can get the last NAVs for the five or six funds of my portfolio, and display them all at once in a dialog box onscreen. Starting with Apple’s Get Quote example, and using values I found in the description of the GetQuickQuote operation on xmethods.net, I get the following error message:

Server was unable to process request. → Object reference not set to an instance of an object.

I would like to use this thread on this bbs to post examples of working SOAP calls to xmethod’s services that are not explicitly demonstrated elsewhere, but it’s not easy to get help from the services themselves. Cdyne’s representative stopped answering my pestering emails after he advised me to include a License Key parameter, which I did, though to no avail. Here’s my variation to Apple’s script as it stands now:

(*
URL Discontinued Services

*)

– SET THE DEFAULT VALUES
property SOAP_Endpoint_URL : “Discontinued Services
property SOAP_app : “”
property method_name : “GetQuickQuote”
property method_namespace_URI : “http://ws.cdyne.com/
property SOAP_action : “http://ws.cdyne.com/GetQuickQuote

– QUERY USER FOR THE STOCK INDICATOR
set this_text to “AAPL”
repeat
try
display dialog “Stock Quote” & return & return & ¬
“Enter the company code:” default answer this_text
set this_text to the text returned of the result
exit repeat
on error number error_number
if the error_number is -128 then error number -128
beep
end try
end repeat

– CREATE THE PARAMETER RECORD
set the method_parameters to {Symbol:this_text, licenseKey:“0”}

– CALL THE SOAP SUB-ROUTINE
copy my SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_URI, method_parameters, SOAP_action) to {call_indicator, call_result}
if the call_indicator is false then
beep
display dialog “An error occurred.” & return & return & call_result buttons {“Cancel”} default button 1
else
display dialog "The delayed stock quote for " & this_text & " is: " & call_result buttons {“OK”} default button 1
end if

on SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_URI, method_parameters, SOAP_action)
try
using terms from application “http://www.apple.com/placebo
tell application SOAP_Endpoint_URL
set this_result to call soap ¬
{method name:method_name ¬
, method namespace uri:method_namespace_URI ¬
, parameters:method_parameters ¬
, SOAPAction:SOAP_action}
end tell
end using terms from
return {true, this_result}
on error error_message number error_number
if the error_number is -916 then ¬
set the error_message to “The script was unable to establish a connection to the Internet.”
return {false, error_message}
end try
end SOAP_call

I finally gave up on using SOAP calls for this project. A better way was suggested by Kirk McElhearn, thank you very much. Applescript’s DO SHELL SCRIPT command returns whatever text the unix shell puts out (or in–I have to read Kirk’s book about shell commands to see what’s going on here), and curl is a unix command that can get a web page into the standard input buffer (I guess). Once in, the text of the page can be searched for the info you need using another command, grep, which finds whole lines of text having the given search string. A third command, cut, is used here to ferret out just the sought characters - the net asset values of my funds.

Thanks also to Bob Y of Bob’s Mutual Funds Page, whose web site turned out to be very searchable and easy to use, both by just browsing it, and by using curl and grep:

http://customer.wcta.net/roberty/index.html

– My Portfolio

set funds to {“BUFSX”, “PRFDX”, “PRSCX”, “SCGEX”, “SMTVX”, “VGHCX”}
set shares to {241.354, 434.764, 293.067, 558.729, 334.741, 181.834}
set NAVs to {“”}
set numFunds to length of funds

set thisDate to date string of (current date)

set NAVs to NAVs & (do shell script “curl -s www.buffalofunds.com/index.html | grep BUFSX | grep '> ’ | cut -c 379-383”)
set NAVs to NAVs & (do shell script “curl -s customer.wcta.net/roberty/XP.HTM | grep PRFDX | cut -c 114-119”)
set NAVs to NAVs & (do shell script “curl -s customer.wcta.net/roberty/XP.HTM | grep PRSCX | cut -c 118-122”)
set NAVs to NAVs & (do shell script “curl -s customer.wcta.net/roberty/XS.HTM | grep SCGEX | cut -c 114-118”)
set NAVs to NAVs & (do shell script “curl -s customer.wcta.net/roberty/XS.HTM | grep SMTVX | cut -c 114-118”)
set NAVs to NAVs & (do shell script “curl -s customer.wcta.net/roberty/XV.HTM | grep VGHCX | cut -c 113-118”)

set NAVs to the rest of NAVs

set value to 0
set Total to 0
set msgString to "John’s Portfolio as of " & thisDate & return & return & “Fund Shares NAV Value” & return & return

repeat with loopVar from 1 to numFunds
set theseShares to item loopVar of shares
set thisNAV to item loopVar of NAVs as real
set msgString to msgString & item loopVar of funds & tab & tab & tab & theseShares & tab & tab & tab & thisNAV & tab & tab & tab
set value to theseShares * thisNAV
set value to value as integer
set Total to Total + value
set msgString to msgString & “$” & value & return
end repeat

set msgString to msgString & return & “Total value now: $” & Total & return
display dialog msgString

Tabs don’t seem to act in AppleScript dialog displays the way they do in other programs. Does anyone know a good way to format data in nice neat tables? Or how to change the font of display dialogs? A monospace font like Courier would look a lot better than Arial can show a table.

Hi jgthomas,

AppleScript’s dialogs are very basic. If you want tables, then AppleScript Studio tables are quite easy to make. The only tricky part is understanding the data sources and connecting them with the ui in Interface Builder (IB). There is a good example of how to sort these tables in the Table Sort example, but you have to make sure you’re connecting the script to the NSTableView in IB and not the scroll view or something like that. Afterwards, you could maybe sort the stocks.

For help, there is the AppleScript Studio section of this bb.

gl,

Right. AS Studio is next on my list. Thanks.