- "Provider agent" implements a Web service
- "Requester agent" (a.k.a. "client") makes use of that Web service
- WSD(Web Service Description) represents a "contract"
- Specifies the message formats, transport protocols, locations
1. Find a Remote Web Service/ Webservice
2. Create a dynamic proxy from WSDL(Web Service Description Language)
Run generator on terminal by either $JAVA_HOME/Commands or $JAVA_HOME/bin/wsimport URL
In our case that is:
$ /usr/lib/jvm/java-6-sun-1.6.0.16/bin/wsimport -d ./TranslatorWS http://www.webservicex.net/TranslateService.asmx?wsdl
Result: It will generate bunch of .class files under ./TranslatorWS folder
3. Generate a jar file from the generated .class files
Run on terminal:
$ jar cvf TranslatorWS.jar -C ./TranslatorWS/ .
4. Write Client code

(Note: Inside src is com folder. Inside com is client folder. Inside client folder is the Java class)
Result: You are able to create the code to utilized the web service.
package com.client;
import net.webservicex.Translate;
import net.webservicex.TranslateService;
import net.webservicex.TranslateServiceSoap;
public class TranslatorWS {
/**
* * @param args
* */
public static void main(String[] args) {
if (args.equals(null) || args.length == 0){
printHelp();
}
TranslateServiceSoap translatorService = new TranslateService().getTranslateServiceSoap();
if ("EnglishTOFrench".equals(args[0])){
System.out.println("Translation:");
System.out.println(translatorService.translate(args[0], args[1]));
}
}
private static void printHelp() {
System.out.println("TranslatorWS <language> <Word To Translate>");
}
}
5. Compile Client Code
RUN on terminal:
$ javac -classpath ./TranslatorWS.jar -d ./bin/ -verbose ./src/com/client/TranslatorWS.java
Result : compiled client code under ./bin directory.
6. Run the client to utilize remote web service
Error occured when translating text please contact support@webservicex.net
0 comments :
Post a Comment