SOAP Calls

Here is a general routine for SOAP calls as well as some useful (well, most of them), specific examples. For more SOAP services, check out [http://www.xmethods.com].

OS version:

property the_directions : {"en_zh", "en_fr", "en_de", "en_it", "en_ja", "en_ko", "en_pt", "en_es", "zh_en", "fr_en", "fr_de", "de_en", "de_fr", "it_en", "ja_en", "ko_en", "pt_en", "ru_en", "es_en"}

--SOAP_on_the_couch()
--copy my SOAP_convert_number_to_words(123) to {call_success, the_num_as_words}
--copy my SOAP_get_distance("10001", "20001") to {call_success, the_distance} --in miles
--copy my SOAP_get_city("10001") to {call_success, the_city}
--copy my  SOAP_get_state("10001") to {call_success, the_state}
--copy my  SOAP_get_location("10001") to {call_success, the_location}
--copy my SOAP_get_synonyms("synonym") to {call_success, the_synonyms}
--copy my SOAP_get_stock_quote("AAPL") to {call_success, the_quote}
--copy my SOAP_translate_text("This is not a pipe.", "en_fr") to {call_success, the_translated_text} --see above for the possible translations

on SOAP_on_the_couch()
	copy my SOAP_ask_Eliza("Hello") to {call_success, the_result}
	repeat
		repeat
			set the_results to (display dialog the_result default answer "" buttons {"Quit", "Answer"} default button 2 with icon 1)
			if button returned of the_results = "Quit" then exit repeat
			if text returned of the_results is not "" then exit repeat
		end repeat
		if button returned of the_results = "Quit" then exit repeat
		copy my SOAP_ask_Eliza(text returned of the_results) to {call_success, the_result}
	end repeat
end SOAP_on_the_couch

on SOAP_ask_Eliza(the_string)
	set method_name to "Eliza"
	set SOAP_Endpoint_URL to "http://www.x-ws.de/cgi-bin/eliza/chat.wsdl"
	set SOAP_action to "#Eliza"
	set method_namespace_uri to "SoapInterop"
	set method_parameters to {|Say|:the_string}
	return my SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_uri, method_parameters, SOAP_action)
end SOAP_ask_Eliza

on SOAP_convert_number_to_words(the_num)
	set method_name to "NumToWords_English"
	set SOAP_Endpoint_URL to "http://www2.tankebolaget.com:8080/scripts/NumToWords.dll/soap/INumToWords"
	set SOAP_action to "urn:NumToWordsIntf-INumToWords#NumToWords_English"
	set method_namespace_uri to "urn:NumToWordsIntf-INumToWords"
	set method_parameters to {aNumber:the_num}
	return my SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_uri, method_parameters, SOAP_action)
end SOAP_convert_number_to_words

on SOAP_get_distance(from_zip, to_zip)
	set method_name to "getDistance"
	set SOAP_Endpoint_URL to "http://webservices.imacination.com/distance/Distance.jws"
	set SOAP_action to "http://webservices.imacination.com/distance/Distance.jws#getDistance"
	set method_namespace_uri to "http://webservices.imacination.com/distance/Distance.jws"
	set method_parameters to {fromZip:from_zip, toZip:to_zip}
	return my SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_uri, method_parameters, SOAP_action)
end SOAP_get_distance

on SOAP_get_city(the_zip)
	set method_name to "getCity"
	set SOAP_Endpoint_URL to "http://webservices.imacination.com/distance/Distance.jws"
	set SOAP_action to "http://webservices.imacination.com/distance/Distance.jws#getCity"
	set method_namespace_uri to "http://webservices.imacination.com/distance/Distance.jws"
	set method_parameters to {zip:the_zip}
	return my SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_uri, method_parameters, SOAP_action)
end SOAP_get_city

on SOAP_get_state(the_zip)
	set method_name to "getState"
	set SOAP_Endpoint_URL to "http://webservices.imacination.com/distance/Distance.jws"
	set SOAP_action to "http://webservices.imacination.com/distance/Distance.jws#getState"
	set method_namespace_uri to "http://webservices.imacination.com/distance/Distance.jws"
	set method_parameters to {zip:the_zip}
	return my SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_uri, method_parameters, SOAP_action)
end SOAP_get_state

on SOAP_get_location(the_zip)
	set method_name to "getLocation"
	set SOAP_Endpoint_URL to "http://webservices.imacination.com/distance/Distance.jws"
	set SOAP_action to "http://webservices.imacination.com/distance/Distance.jws#getLocation"
	set method_namespace_uri to "http://webservices.imacination.com/distance/Distance.jws"
	set method_parameters to {zip:the_zip}
	return my SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_uri, method_parameters, SOAP_action)
end SOAP_get_location

on SOAP_get_synonyms(the_word)
	set method_name to "getServiceResponsePublic"
	set SOAP_Endpoint_URL to "http://www.extensio.com:8080/ExtensioInfoServer/servlet/rpcrouter"
	set SOAP_action to "urn:MBWS-SoapServices#getServiceResponsePublic"
	set method_namespace_uri to "urn:MBWS-SoapServices"
	set method_parameters to {serviceName:"Synonym", inputText:the_word}
	return my SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_uri, method_parameters, SOAP_action)
end SOAP_get_synonyms

on SOAP_get_stock_quote(the_symbol)
	set method_name to "getQuote"
	set SOAP_Endpoint_URL to "http://66.28.98.121:9090/soap"
	set SOAP_action to "urn:xmethods-delayed-quotes#getQuote"
	set method_namespace_uri to "urn:xmethods-delayed-quotes"
	set method_parameters to {symbol:the_symbol}
	return my SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_uri, method_parameters, SOAP_action)
end SOAP_get_stock_quote

on SOAP_translate_text(the_text, the_direction)
	set method_name to "BabelFish"
	set SOAP_Endpoint_URL to "http://services.xmethods.net:80/perl/soaplite.cgi"
	set SOAP_action to "urn:xmethodsBabelFish#BabelFish"
	set method_namespace_uri to "urn:xmethodsBabelFish"
	set method_parameters to {translationmode:the_direction, sourcedata:the_text}
	return my SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_uri, method_parameters, SOAP_action)
end SOAP_translate_text

--***********************************-- main soap call --***********************************--

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 the_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, the_result}
	on error error_message number error_number
		if error_number = -916 then ¬
			set error_message to "The script was unable to establish a connection to the Internet."
		return {false, error_message}
	end try
end SOAP_call