Web services simple application - how to implement?

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

Web services simple application - how to implement?

Postby Edmilson Bringel » Wed Dec 19, 2007 9:52 am

I need to create an application which invokes some web-services (RPC - So, I don't have "wsdl" available).

Please, does anybody can help me in this login example?

I have to send the xml below:

<?xml version="1.0" ?>
- <methodCall>
<methodName>Autenticacao.Login</methodName>
- <params>
- <param>
- <value>
- <struct>
- <member>
<name>login</name>
- <value>
<string>my_user_id</string>
</value>
</member>
- <member>
<name>password</name>
- <value>
<string>my_password</string>
</value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>

The web-service response will be the xml below:

<?xml version="1.0" ?>
- <methodResponse>
- <params>
- <param>
- <value>
<string>...an string session id...</string>
</value>
</param>
</params>
</methodResponse>

So, I know that I have to create a class which will serialize itself to generate the login xml and sent it to the web service address.
Again, I have to have a class to instance the response xml and so on...

I don't know "how" to do that.

I read the web services manual but I can't go from concept to practice...

Any help will be very appreciated..

Edmilson Bringel
Edmilson Bringel
Apprise Consulting - Brazil
Edmilson Bringel
 
Posts: 6
Joined: Sat Nov 24, 2007 8:26 am
Location: Brazil

Postby tc » Wed Dec 19, 2007 10:12 am

Hello,

When invoking a web service, knowing the URL of the WSDL file is crucial. The WSDL file describes what services are available and the URL of the server that actually does the work. The server that actually implements the web service and the server that has the WSDL file may be different.

To see examples, go to http://www.xmethods.net/ and browse the services available. I think there is 'List all' button to list all the services, look at the ones that say 'RPC' and select one. The next page, after selecting, has the address of the WSDL file, simply enter that URL in a browser and you can see the WSDL.

To call the web service from VA Smalltalk, do something like:
Code: Select all
SstWSContainer clearAll.
[
   | aContainer aServiceCollection aService containerName |

   containerName := 'MyContainer'.
    aContainer := SstWSContainer containerNamed:  containerName
      ifNone: [ SstWSContainer createContainerNamed: containerName ].
   aServiceCollection := aContainer deploy: 'http://webservices.imacination.com/distance/Distance.jws?wsdl'.
   aService := aServiceCollection first.
   (aService invoke: 'getDistance' withArguments: #('37363' '23234')) inspect.
] fork.


. . . the above is for RPC, doc/literal is different. Also note the 'deploy:' has the URL of the WSDL file. Instantiations also has some papers written that walk you through XML, SOAP, and web service examples. I can't do attachments here but send mail to vast-support@instantiations.com.

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC

Postby Edmilson Bringel » Wed Dec 19, 2007 11:53 am

Thank you for reply!

I have reached exactly that point, but with this:

[ | aContainer aServiceCollection|
aContainer := SstWSContainer containerNamed: SciSocketManager default getHostName.
aServiceCollection := aContainer deploy:
'http://www.thomas-bayer.com/names-service/soap?wsdl'.
( aServiceCollection first invoke: 'getCountries:' withArguments: #('*') ) inspect ] fork

In both cases I get:

No port found for passed operation and arguments

But, I think that at this point I can use web services by solving the port problem and go ahead...

My question is not about to use web services with wsdl available.
My problem is how to use web services with no wsdl.

I am thinking about to write all the code (to connect http, serialize/deserialize classes, send, receive, ...) But, before to decide that, I would like to know if there is a rapid way to do that (something already done).

I agree about question "why the developer did not put available the wsdl files...maybe because it was written in php?!?! anyway, I have no control about that...I have to integrate my app with that web services and all I have is an "xml layout based documentation".

Any reply will be very very helpful!

P.S. Any tip about the port error, also!
Edmilson Bringel
Apprise Consulting - Brazil
Edmilson Bringel
 
Posts: 6
Joined: Sat Nov 24, 2007 8:26 am
Location: Brazil

Postby tc » Wed Dec 19, 2007 12:17 pm

Hello,

The portType is the section of the WSDL which has the suppported functions. Looking at the WSDL, I do not see 'getCountries:' listed but here is another example:
Code: Select all
SstWSContainer clearAll.
[
   | aContainer aServiceCollection aService containerName |

   containerName := 'MyContainer'.
    aContainer := SstWSContainer containerNamed:  containerName
      ifNone: [ SstWSContainer createContainerNamed: containerName ].
   aServiceCollection := aContainer deploy: 'http://webservices.imacination.com/distance/Distance.jws?wsdl'.
   aService := aServiceCollection first.
   (aService invoke: 'getCity' withArguments: #('37363')) inspect.
] fork.


You need one other piece of information if you do not have the WSDL, the server that provides the service. For the above, the server is:

http://webservices.imacination.com/dist ... stance.jws

. . . which is listed in the 'wsdl:service' tag. I've never tried a web service without a WSDL file, so, duplicating all the things that happen in a container will require some research. However, having the address of the server providing the service is a must.

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC

Postby tc » Wed Dec 19, 2007 3:27 pm

Hello,

Correction on the service you called, that service is DOC/Literal, the services you want are listed as RPC in the xmethods list.

Also, that service appears to have a wrapped style of parameters which someone is working on now.

Here is an example of calling a doc/literal service:
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 = 'GetPresidentsDay' ].
       mappedElement := schema asMappedElement.
        mappedElement year: '2008'.
        ((aServiceCollection first) invoke: 'GetPresidentsDay' withArguments: (Array with: mappedElement)) inspect
   ] fork


When the inspector pops up, do 'self abtXmlPrintString' to see the data returned.

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC

Postby Edmilson Bringel » Fri Dec 21, 2007 1:02 pm

Hello,

Thank you for the informations...Now, I can progress with my work.

Well, I have the address of the server providing the service...but it answer to my "...?wsdl" request's with a kind of fault code (because really, wsdl does not exist!).

that's it: "http://www.redesecovi.com.br/webservices.v.1.2/servidor_carga_testes.php"

I suggested to the people who have developed the web services that I have to use to publish the wsdl files (but I don't think that they will do...) Their answer was something about "xml-rpc does not use wsdl..."

Anyway, I will try to evolve with the manual concepts and with the information that you provide me.

Thanks a lot!
Edmilson Bringel
Apprise Consulting - Brazil
Edmilson Bringel
 
Posts: 6
Joined: Sat Nov 24, 2007 8:26 am
Location: Brazil

Postby marten » Sat Dec 22, 2007 10:40 am

Their answer was something about "xml-rpc does not use wsdl..."



Which seems to be correct ...

Marten
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Postby tc » Sun Dec 23, 2007 12:51 am

Hello,

WSDL only provides the description of what services are available. When I saw the words 'web service', that came to mind as part of the solution. However, to do RPC, it will probably be sent as a SOAP message and your example in a previous message will require more than the XML you provided. Here is an example of a SOAP message doing an RPC call to 'getCity' for zip code 40290.

Code: Select all
  <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
  <SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SOAP-ENV:Body>
  <mns:getCity xmlns:mns="http://DefaultNamespace"
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <zip xsi:type="xsd:string">40290</zip>
  </mns:getCity>
  </SOAP-ENV:Body>
  </SOAP-ENV:Envelope>


In the method:

SstHttpClient>>#post:typed:at:using:withHeaders:

. . . I modified the line:

httpResponse := self send: httpRequest to: tUrl.

. . . to:

httpRequest header at: 'SOAPACTION:' put: '""'.
httpResponse := self send: httpRequest to: tUrl.

. . . and inspected the following:

'http://webservices.imacination.com/distance/Distance.jws' sstAsUrl post: str

. . . where 'str' is the SOAP message above. The change can be incorporated in your app by creating a new method or creating a subclass.

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest