PageRenderTime 81ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/Tcl Web Service Example.html

http://tclws.googlecode.com/
HTML | 126 lines | 116 code | 10 blank | 0 comment | 0 complexity | 5ab875d948dfb92b079d26fb1865de9c MD5 | raw file
  1. <HTML lang=en dir=ltr xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  2. <HEAD>
  3. <TITLE>Tcl Web Service Example</TITLE>
  4. <META http-equiv=Content-Type content="text/html; charset=utf-8">
  5. <META content="Tcl Web Service Example" name=KEYWORDS>
  6. </HEAD>
  7. <BODY>
  8. <H1>Tcl Web Service Example</H1>
  9. <A name=Server_Side></A>
  10. <H2>Server Side </H2>
  11. <P>
  12. The following is placed in the httpdthread.tcl:
  13. </P>
  14. <PRE> package require WS::Server
  15. package require WS::Utils
  16. </PRE>
  17. <P>
  18. The following is placed in the a file in the custom directory:
  19. </P>
  20. <PRE>
  21. ##
  22. ## Define the service
  23. ##
  24. &nbsp;::WS::Server::Service \
  25. -service wsExamples \
  26. -description {Tcl Example Web Services} \
  27. -host $::Config(host):$::Config(port)
  28. </PRE><PRE> ##
  29. ## Define any special types
  30. ##
  31. &nbsp;::WS::Utils::ServiceTypeDef Server wsExamples echoReply {
  32. echoBack {type string}
  33. echoTS {type dateTime}
  34. }
  35. </PRE><PRE> ##
  36. ## Define the operations available
  37. ##
  38. &nbsp;::WS::Server::ServiceProc \
  39. wsExamples \
  40. {SimpleEcho {type string comment {Requested Echo}}} \
  41. {
  42. TestString {type string comment {The text to echo back}}
  43. } \
  44. {Echo a string back} {
  45. </PRE><PRE> return [list SimpleEchoResult $TestString]
  46. }
  47. </PRE>
  48. <P><BR></P><PRE> &nbsp;::WS::Server::ServiceProc \
  49. wsExamples \
  50. {ComplexEcho {type echoReply comment {Requested Echo -- text and timestamp}}} \
  51. {
  52. TestString {type string comment {The text to echo back}}
  53. } \
  54. {Echo a string and a timestamp back} {
  55. </PRE><PRE> set timeStamp [clock format [clock seconds] -format {%Y-%m-%dT%H:%M:%SZ} -gmt yes]
  56. return [list ComplexEchoResult [list echoBack $TestString echoTS $timeStamp] ]
  57. }
  58. </PRE>
  59. <P><BR></P>
  60. <A name=Client_Side></A>
  61. <H2>Client Side </H2><PRE> package require WS::Client
  62. </PRE><PRE> ##
  63. ## Get Definition of the offered services
  64. ##
  65. &nbsp;::WS::Client::GetAndParseWsdl http://localhost:8015/service/wsExamples/wsdl
  66. </PRE><PRE> set testString "This is a test"
  67. set inputs [list TestString $testString]
  68. </PRE><PRE> ##
  69. ## Call synchronously
  70. ##
  71. puts stdout "Calling SimpleEcho via DoCalls!"
  72. set results [::WS::Client::DoCall wsExamples SimpleEcho $inputs]
  73. puts stdout "\t Received: {$results}"
  74. </PRE><PRE> puts stdout "Calling ComplexEcho via DoCalls!"
  75. set results [::WS::Client::DoCall wsExamples ComplexEcho $inputs]
  76. puts stdout "\t Received: {$results}"
  77. </PRE>
  78. <P><BR></P><PRE> ##
  79. ## Generate stubs and use them for the calls
  80. ##
  81. &nbsp;::WS::Client::CreateStubs wsExamples
  82. puts stdout "Calling SimpleEcho via Stubs!"
  83. set results [::wsExamples::SimpleEcho $testString]
  84. puts stdout "\t Received: {$results}"
  85. </PRE><PRE> puts stdout "Calling ComplexEcho via Stubs!"
  86. set results [::wsExamples::ComplexEcho $testString]
  87. puts stdout "\t Received: {$results}"
  88. </PRE><PRE> ##
  89. ## Call asynchronously
  90. ##
  91. proc success {service operation result} {
  92. global waitVar
  93. </PRE><PRE> puts stdout "A call to $operation of $service was successful and returned $result"
  94. set waitVar 1
  95. }
  96. </PRE><PRE> proc hadError {service operation errorCode errorInfo} {
  97. global waitVar
  98. </PRE><PRE> puts stdout "A call to $operation of $service was failed with {$errorCode} {$errorInfo}"
  99. set waitVar 1
  100. }
  101. </PRE><PRE> set waitVar 0
  102. puts stdout "Calling SimpleEcho via DoAsyncCall!"
  103. &nbsp;::WS::Client::DoCall wsExamples SimpleEcho $inputs \
  104. [list success wsExamples SimpleEcho] \
  105. [list hadError wsExamples SimpleEcho]
  106. vwait waitVar
  107. </PRE><PRE> puts stdout "Calling ComplexEcho via DoAsyncCall!"
  108. &nbsp;::WS::Client::DoCall wsExamples ComplexEcho $inputs \
  109. [list success wsExamples SimpleEcho] \
  110. [list hadError wsExamples SimpleEcho]
  111. vwait waitVar
  112. </PRE><PRE> exit
  113. </PRE>
  114. <P><BR></P>
  115. </BODY>
  116. </HTML>