To access some external services there is a protocol called SOAP. Now ICM can send a SOAP request and get the result back to ICM.
Sending request to the SOAP server
A SOAP request is a special XML text which contains :
- the SOAP method name and a name-space
- the method arguments
In ICM you can form a SOAP message using the SoapMessage function. It creates a special
soapMessage object which holds SOAP method name and it's arguments.
Example:
# create a message with SOAP method and a namespace
req = SoapMessage( "doSpellingSuggestion","urn:GoogleSearch" )
# add method arguments
req = SoapMessage( req, "key","btnHoYxQFHKZvePMa/onfB2tXKBJisej" ) # get key from google
req = SoapMessage( req, "pharse", "Bretney Spers" ) # some misspelled pharse
Once the message is ready it can be send to the server using the read http command.
read string s_soapServiceURL + " " + String( soapMessage )
The result of the server response will be stored into s_out variable. It can be
parsed to a soapMessage object using the SoapMessage function.
Example:
HTTP.postContentType = "text/xml"
read string "http://api.google.com/search/beta2" + " " + String(req)
res = SoapMessage( s_out )
if Error(res) == "" then
# process message
endif
Processing SOAP results
To access the content of SOAP message, the Value function is applied
If the result of the SOAP response is a simple value, such as integer,`real,`string,`sarray,`rarray,`iarray, then it will be automatically casted to the corresponding ICM type. Otherwise a special type of parray will be returned.
In some cases the result returned by SOAP server is actually some complex data structure (not just a single string or number) The most common complex SOAP types are 'struct' and 'array'. Each of them can either contain a simple type of other 'struct' or 'array'.
You may navigate through this structure using index expressions:
soapObject[ i_integerIndex ]
or
soapObject[ s_stringIndex ]
The number of elements in the array of struct can be returned by Nof function.
Sarray of field names of a struct can be returned by Name function
For example the following code navigates through the result obtained from the google search service.
res = Value( SoapMessage( s_out ) )
s_html = ""
s_html += "Searched web for <b>" + res["searchQuery"] + "</b>. Search took " + res["searchTime"] + " seconds.<br>"
elements = res["resultElements"]
for i=1,Nof(elements)
resElement = elements[i]
s_html += "<br>"
cat = String( resElement["directoryCategory"]["fullViewableName"] )
summary = String( resElement["summary"] )
title = String( resElement["title"] )
snippet = String( resElement["snippet"] )
url = String( resElement["URL"] )
cachedSize = String( resElement["cachedSize"] )
if (Length(title) != 0) then
s_html += "<font color=\"#0000FF\"><b><u>" + title + "</u></b></font><br>"
else
s_html += "<font color=\"#0000FF\"><b><u>" + url + "</u></b></font><br>"
endif
if (Length(snippet) != 0) s_html += snippet + "<br>"
if (Length(summary) != 0) s_html += "<font color=\"#808080\">Description:</font> " + summary + "<br>"
if (Length(cat) != 0) s_html += "<font color=\"#808080\">Category: <u>" + cat + "</u></font><br>"
if (Length(title) != 0) s_html += "<font color=\"#008000\"><u>" + url + "</u> - " + cachedSize + "</font><br>"
endfor
{ KEGG database }
KEGG (Kyoto Encyclopedia of Genes and Genomes) is a database resource that integrates genomic, chemical, and systemic functional information. In particular, gene catalogs in the completely sequenced genomes are linked to higher-level systemic functions of the cell, the organism, and the ecosystem.
Example of few requests:
l_info = l_commands = no
HTTP.postContentType = "text/xml"
HTTP.soapAction = "SOAP/KEGG"
url = "http://soap.genome.jp/keggapi/request_v6.2.cgi"
req=SoapMessage( "get_pathways_by_genes" "SOAP/KEGG" )
req=SoapMessage( req "genes_id_list", {"hsa:5292"} )
read string url+" "+String(req)
sss = SoapMessage( s_out )
if (Error(sss) == "") then
S_path = Value(sss)
print "pathways = " Sum(S_path,",")
for i=1,Nof(S_path)
req=SoapMessage( "get_references_by_pathway" "SOAP/KEGG" )
req=SoapMessage( req "pathway_id", S_path[i] )
read string url+" "+String(req)
sss = SoapMessage( s_out )
print "references for " S_path[i]
Value(sss)
endfor
endif
For KEGG WSDL file click here. API is defined here
Related functions: SoapMessage Value Error Nof Type Name