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