Homepage › Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › Calling a web service from tcl.
- This topic has 7 replies, 2 voices, and was last updated 18 years, 6 months ago by Todd Yingling.
-
CreatorTopic
-
March 22, 2006 at 7:09 pm #48420Todd YinglingParticipant
Has anyone called a web service on a web server from their tcl proc? Is this possible? If so, can you explain how?
Thanks,
-
CreatorTopic
-
AuthorReplies
-
-
March 23, 2006 at 8:28 pm #58588Todd YinglingParticipant
Maybe I need to use the http client to get what I want. What I would like to do is send data to a web server where a web service queries a db for some data and sends that data back to cloverleaf.
Thanks,
-
March 23, 2006 at 9:40 pm #58589Mike ShoemakerParticipant
Hey Todd, I tried using SOAP to call a webservice from a tcl proc, but could never get the TCL-SOAP packages to behave themselves. I ended up simply using the HTTP client tcl package to post an HL7 message (or XML for that matter) to a webservice or at least a “webserver”.
Basically I send an HL7 message to a url and they send me back an ack message. Once they get the message they do some kind of .net magic and fill a database with what i send them. Their ack message is simply a “thanks we got it ok” message, but i’m sure they could accept a message and process it and then send something back to me just as easy.
Let me know if you want details.
Mike
-
March 24, 2006 at 1:32 pm #58590Todd YinglingParticipant
Thanks for the reply. That’s what I am trying to do with the addition the webserver sending back an XML message with the data that the .NET program queried.
I haven’t set up a thread to translate HL7 to XML and send it to a webserver yet; therefore, my questions may seem basic to you.
The driver protocol I’m using is http Client, the Driver mode is message driven and the Query TPS is httpquery. I assume I need to use a xlate to convert the HL7 msg to an XML message?
Thanks for you help.
-
March 24, 2006 at 2:57 pm #58591Mike ShoemakerParticipant
Hey Todd, In theory you are correct with the HTTP client protocol. In reality, I did not have any success with that. Everytime i tried to send a message, the process would panic. I ended up writing a tps proc that would translate to XML and then post the result to the webservice. I have this proc on the Outbound TPS of the sending thread. I also wrote a little to handle the server response which was in xml but we changed that to a simple 0 or 1 for ack and nak. I was able to receive the xml message they were sending in response but didnt want to go through parsing it out. If you want, i can share the code i have.
thanks
-
March 24, 2006 at 3:25 pm #58592Todd YinglingParticipant
Mike, That would be great. If you don’t mind, it would be nice to take a look at your code. I appreciate it.
I’m all too familiar with cloverleaf’s panics.
Thanks,
-
March 24, 2006 at 3:42 pm #58593Mike ShoemakerParticipant
Hey Todd, Here is the package that connects and sends data to a webservice. Basically, you call this with 3 parameters:
inDatais the data (string) to be sent to the webservice inUrlis the url of the webservice inParamis the parameter used in the url of the webservice. The statement
set query2 [::http::formatQuery $queryParam $xml_data]will gather the data string and the parameter and format a query sting. The statment set
http [::http::geturl $url -query $query2]will do the work basically and post the data to the url supplied using the properly formated query created in the statement above. The rest of the code is for handling the responses. There are 2 types, the HTTP response which is from the web server (an example is a 404 not found error when requesting a page) and the HTML error which is the response from the webservice code (this is where your xml response would be)
Code:package require http
package require WebServiceAckNakproc webServiceConn { inData inUrl inParam } {
set html “”
set url $inUrl
set xml_data $inData
set queryParam $inParamset query2 [::http::formatQuery $queryParam $xml_data]
if {![catch {set http [::http::geturl $url -query $query2]} error_msg ]} {
set html [::http::data $http]
upvar #0 $http status
foreach index [array names status] {
switch -exact — $index {
querylength { set query_len [array get status $index] }
currentsize { set response_len [array get status $index] }
http { set http_status [array get status $index] }
default { }
}
}set http_status [lindex $http_status 1]
set ackNak [webServiceAckNak $http_status $html]return $ackNak
} else {
echo “error has been encountered::$error_msg”
}
if {$html != “”} {
[::http::cleanup $html]
}
}The second package i have handles the server and html responsed.
Code:proc webServiceAckNak { inHTTP inHTML } {
set result “”
set httpResponse $inHTTP
set htmlResponse $inHTMLset htmlResponseString [lindex [split $htmlResponse n] 1]
regexp >(.*?) $htmlResponseString match result
if {$result == “working”} {
return 0
} else {echo $htmlResponse
echo $httpResponse}
}
To configure this in the engine, i use a raw route for the messages i want to send and configure the proc on the outbound tps. The outbound tps proc contains all the translation for the message and then at the end i call the webservice proc as:
Code:
set res [webServiceConn $msg $url $queryParameter]
if {$res == 0} {
set status_cond 1
echo “Message Sent Successfully.”
} else {
set status_cond 0
echo “An error has been encountered with the webservice connection. Retrying…COUNT: $counter”
}
Let me know if you need more details with the code, i’m happy to help.
Have fun!
Mike
-
March 24, 2006 at 4:33 pm #58594Todd YinglingParticipant
Thanks Mike – I will maul it over after lunch.
-
-
AuthorReplies
- The forum ‘Cloverleaf’ is closed to new topics and replies.