Hello,
There are a few ways to do that. First, here is a doc/literal web service that gets the new year date for a given year:
- Code: Select all
SstWSContainer clearAll.
[
| aContainer aServiceCollection contName parm |
contName := SciSocketManager default getHostName.
aContainer := SstWSContainer containerNamed: contName
ifNone: [ SstWSContainer createContainerNamed: contName ].
aServiceCollection := aContainer
deploy: 'http://www.holidaywebservice.com/Holidays/US/Dates/USHolidayDates.asmx?WSDL'.
schemas := (aContainer serializationManager schemas at: 'http://www.27seconds.com/Holidays/US/Dates/') content.
schema := schemas detect: [ :s | s name = 'GetNewYear' ].
mappedElement := schema asMappedElement.
mappedElement year: '2008'.
((aServiceCollection first) invoke: 'GetNewYear' withArguments: (Array with: mappedElement)) inspect
] fork
An instance of SstSoapMappedElement is returned. One way to proceed is to look at the XML by sending abtXmlPrintString to this object, which results in:
- Code: Select all
'<GetNewYearResponse
xmlns="http://www.27seconds.com/Holidays/US/Dates/">
<GetNewYearResult>2008-01-01T00:00:00.0000000-05:00</GetNewYearResult>
</GetNewYearResponse>'
. . . and getting the name of the element of interest, such as 'GetNewYearResult'. Once the element name is known, the following can be done:
- Code: Select all
anSstSoapMappedElement getObjectNamed: 'GetNewYearResult'
. . . this code can be executed in the block above. Another way to get the result is by iterating over the elements. For example, one could do the following:
- Code: Select all
anSstSoapMappedElement elements inject: Dictionary new into: [ :dict :elem |
elem object isNil
ifFalse: [ dict at: elem abtXmlName put: elem object].
dict ]
To see all the services this web service has, go to
http://www.soapclient.com/soaptest.html and enter the WSDL file address from above,
http://www.holidaywebservice.com/Holidays/US/Dates/USHolidayDates.asmx?WSDL .
Pullling all the above together, here is the script to get the date for Cinco de Mayo for a given year:
- Code: Select all
SstWSContainer clearAll.
[
| aContainer aServiceCollection contName parm soapMappedElement dictionary |
contName := SciSocketManager default getHostName.
aContainer := SstWSContainer containerNamed: contName
ifNone: [ SstWSContainer createContainerNamed: contName ].
aServiceCollection := aContainer
deploy: 'http://www.holidaywebservice.com/Holidays/US/Dates/USHolidayDates.asmx?WSDL'.
schemas := (aContainer serializationManager schemas at: 'http://www.27seconds.com/Holidays/US/Dates/') content.
schema := schemas detect: [ :s | s name = 'GetCincoDeMayo' ].
mappedElement := schema asMappedElement.
mappedElement year: '2008'.
soapMappedElement := ((aServiceCollection first)
invoke: 'GetCincoDeMayo' withArguments: (Array with: mappedElement)).
dictionary := soapMappedElement elements inject: Dictionary new into: [ :dict :elem |
elem object isNil
ifFalse: [ dict at: elem abtXmlName put: elem object].
dict ].
dictionary inspect
] fork
--tc