File: Tcl_Web_Service_Math_Example.html

package info (click to toggle)
tclws 3.5.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 944 kB
  • sloc: tcl: 7,976; makefile: 18
file content (142 lines) | stat: -rw-r--r-- 3,909 bytes parent folder | download | duplicates (5)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<HTML lang=en dir=ltr xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>Tcl Web Service Math Example</TITLE>

<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="Tcl Web Service Math Example" name=KEYWORDS>
<link rel="stylesheet" href="style.css" type="text/css" media="screen">
</HEAD>

<BODY>
<H1>Tcl Web Service Math 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 wsMathExample \
        -description  {Tcl Web Services Math Example} \
        -host         $::Config(host):$::Config(port)

    ##
    ## Define any special types
    ##
    ::WS::Utils::ServiceTypeDef Server wsMathExample Term {
       `coef         {type float}
        powerTerms   {type PowerTerm()}
    }
    ::WS::Utils::ServiceTypeDef Server wsMathExample PowerTerm {
        var          {type string}
        exponet      {type float}
    }
    ::WS::Utils::ServiceTypeDef Server wsMathExample Variables {
        var          {type string}
        value        {type float}
    }

   ##
   ## Define the operations available
   ##
   ::WS::Server::ServiceProc \
        wsMathExample \
        {EvaluatePolynomial {type float comment {Result of evaluating a polynomial}}} \
        {
            varList       {type Variables() comment {The variables to be substitued into the polynomial}}
            polynomial    {type Term() comment {The polynomial}}
        } \
        {Evaluate a polynomial} {
        set equation {0 }
        foreach varDict $varList {
            set var [dict get $varDict var]
            set val [dict get $varDict value]
            set vars($var) $val
        }
        foreach term $polynomial {
            if {[dict exists $term coef]} {
                set coef [dict get $term coef]
            } else {
                set coef 1
            }
            append equation "+ ($coef"
            foreach pow [dict get $term powerTerms] {
                if {[dict exists $pow exponet]} {
                    set exp [dict get $pow exponet]
                } else {
                    set exp 1
                }
                append equation [format { * pow($vars(%s),%s} [dict get $pow var] $exp]
            }
            append equation ")"
        }
        set result [expr $equation]
        return [list SimpleEchoResult $result]
    }
</PRE>
<P><BR></P>

<A name=Client_Side></A>
<H2>Client Side </H2>
<PRE>
    package require WS::Client
    ##
    ## Get Definition of the offered services
    ##
    ::WS::Client::GetAndParseWsdl http://localhost:8015/service/wsMathExamples/wsdl

    dict set term var X
    dict set term value 2.0
    dict lappend varList $term
    dict set term var Y
    dict set term value 3.0
    dict lappend varList $term

    set term {}
    set powerTerm {}
    dict set powerTerm coef 2.0
    dict set term var X
    dict set term pow 2.0
    dict lappend terms $term
    dict set term var Y
    dict set term pow 3.0
    dict lappend terms $term
    dict set powerTerm powerTerms $terms

    dict set powerTerm coef -2.0
    dict set term var X
    dict set term pow 3.0
    dict lappend terms $term
    dict set term var Y
    dict set term pow 2.0
    dict lappend terms $term
    dict set powerTerm powerTerms $terms
    dict lappend polynomial powerTerms $powerTerm

    dict set input [list varList $varList polynomial $polynomial]
    ##
    ## Call service
    ##
    puts stdout "Calling EvaluatePolynomial wiht {$input}"
    set resultsDict [::WS::Client::DoCall wsMathExample EvaluatePolynomial $input]
    puts stdout "Results are {$resultsDict}"
</PRE>
<P><BR></P>

</BODY>
</HTML>