Tuesday, May 12, 2009

Creating HelloWorldClient using SOAP UI Plugin

1. Create a new project for the HelloWorld client (an ordinary Java project is sufficient)




2. Next, we add Glassfish v2 as Server Runtime in Build Path.

3. Right click->BuildPath->Add Library->ServerRuntime->Glassfish v2




4. Select the project and Right Click->Soap UI->Add SOAPUI Nature, SOAP UI WebService item will be added in Project Explorer
(Goto Package Explorer if you don't see the Soap UI menu item)

5. Right Click on SOAP UI and add the WSDL location





6. Select HelloWorldSoapBinding and Right Click->GenerateCode->JAX-WS Artifacts
Enter the appropriate info in the JAX-WS Artifacts window (note you might need to enter full paths if the files are not generated)



7. Click Tools and enter the location of JAX-WS Wsimport, for example c:\glassfish\bin and Click OK


8. Ensure (keep generated class) is checked, then click Generate on JAX-WS Artifacts window, it will display a dialog box that the operation was successful. Switch back to Java Perspective, then refresh the src folder and you can see the wsimport generated classes




9. Click Generate on JAX-WS Artifacts window, it will display a dialog box that the operation was successful. Switch back to Java Perspective, then refresh the src folder and you can see the wsimport generated classes


10. Implement your client code by adding a new class HelloWorldClient






Code:
package sample;

public class HelloWorldClient {

public static void main(String[] args) {

//Create Service
HelloWorldService service = new HelloWorldService();

//Create proxy
HelloWorld proxy = service.getHelloWorld();

//Invoke
System.out.println(proxy.hello("hello"));

}
}


11. Execute the client by selecting the HelloWorldClient in the package explorer of Eclipse and selecting Run>Java Application. In the console window of Eclipse, you should see "Hello World".



That's it! :-)

1 comment:

  1. this is great!! Do you have a similar example on creating the JAX-RPC client using SOAP UI tool?

    ReplyDelete