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