| | 100 | To instantiate and use your WebServicesRoot (MyService in the example above), you can do something like this: |
|---|
| | 101 | |
|---|
| | 102 | cherrypy.root = MyService("http://foo.bar.baz/") |
|---|
| | 103 | |
|---|
| | 104 | The constructor for WebServicesRoot has a required parameter of *baseURL*. This parameter sets the URL path of the web service (which will show up as the web service location in the WSDL). There are two optional parameters that will be derived from the baseURL if you don't provide them. Those parameters are *tns* and *typenamespace*. *tns* is the target namespace declared in the WSDL (the XML namespace for the SOAP operations). *typenamepsace* is the XML namespace for the types defined in the WSDL. *tns* defaults to *baseURL* + "soap/". *typenamespace* defaults to *tns* + "types". |
|---|
| | 105 | |
|---|
| | 106 | URLs |
|---|
| | 107 | ---- |
|---|
| | 108 | |
|---|
| | 109 | class InnerService(WebServicesRoot): |
|---|
| | 110 | @wsexpose(int) |
|---|
| | 111 | def times4(self, num): |
|---|
| | 112 | return num * 4 |
|---|
| | 113 | |
|---|
| | 114 | class ServiceRoot(WebServicesRoot): |
|---|
| | 115 | inner = InnerService() |
|---|
| | 116 | |
|---|
| | 117 | @wsexpose(int) |
|---|
| | 118 | def times2(self, num): |
|---|
| | 119 | return num * 2 |
|---|
| | 120 | |
|---|
| | 121 | Assume that ServiceRoot is instantiated with a *baseURL* of "http://foo.bar.baz/". Here are URLs that are available: |
|---|
| | 122 | |
|---|
| | 123 | +----------------------------------+-------------------------------------------+ |
|---|
| | 124 | | URL | What is it | |
|---|
| | 125 | +==================================+===========================================+ |
|---|
| | 126 | | http://foo.bar.baz/ | nothing there... you could use standard | |
|---|
| | 127 | | | TurboGears expose to put a page there. | |
|---|
| | 128 | +----------------------------------+-------------------------------------------+ |
|---|
| | 129 | | http://foo.bar.baz/times2 | HTTP access to the times2 method | |
|---|
| | 130 | +----------------------------------+-------------------------------------------+ |
|---|
| | 131 | | http://foo.bar.baz/inner/times4 | HTTP access to the times4 method on | |
|---|
| | 132 | | | InnerService + |
|---|
| | 133 | +----------------------------------+-------------------------------------------+ |
|---|
| | 134 | | http://foo.bar.baz/soap/ | URL to POST SOAP requests to | |
|---|
| | 135 | +----------------------------------+-------------------------------------------+ |
|---|
| | 136 | | http://foo.bar.baz/soap/api.wsdl | URL to get the WSDL file from | |
|---|
| | 137 | +----------------------------------+-------------------------------------------+ |
|---|
| | 138 | |
|---|
| | 139 | SOAP method names are created by taking the URL parts and concatenating and |
|---|
| | 140 | camelCasing them. In the example above, there will be a "times2" SOAP method, |
|---|
| | 141 | as you'd expect. The "inner/times4" method will become "innerTimes4" in SOAP. |
|---|
| | 142 | All of the SOAP methods live in a flat namespace and appear in a single WSDL |
|---|
| | 143 | file that covers your whole web service. |
|---|
| | 144 | |
|---|