Andrew Romanenco.com

As web service developer you can work on two main branches: developer server part or develop client one. Whatever side you work on you still need other one for testing purpose. Of course, there is no need in writing test code, as we have soapUI. It can work as test client for some web service, and emulate all calls from WSDL. Also soapUI can work as mock server.
Let's try to make interesting case: we take public available WSDL for any web service, start two instances of soapUI: one instance will become mock server and second will be client. This will show you how easily you can test you web service based applications.

You can use any service you like. For this example I googled for 'get weather wsdl' and have get this url:  http://www.webservicex.net/WeatherForecast.asmx?WSDL Save this or any other wsdl as sample.wsdl
Also, make sure, web service you play with is alive. This one is alive for now (July 2009)

Let's start with client side emulation.
Open soapUI and create new project. Set name to client and choose wsdl you saved before. Leave checkboxes in default values.
After client creation you see tree of all operations service supports, and one of them is GetWeatherByZipCode. Expand it to see default request generated automatically. Open this request.

Double click on Request1 to open its body. As you see, soapUI created it for you with placeholders for required data. Also look at header, it contain web service url - original web url of server serving this request. Replace placeholder with real zip, for example 07203 and run request... In a second you get request from server with data requested. Now you can test remote server, but you want to test your own... let's create it!

Open another instance of soapUI. Create similar project: set its name to Server and use the same wsdl. Right click on created service (WeatherForecastSoap for this example) and choose - Generate Mock Service.
In window opened you can configure port to use, path, operations. In next window, with mock service created, click on any operation to see available responses - GetWeatherByZipCode for example. By default it has only one response - Response1. Click it to see body. As for client side, you see response body with placeholders. As you understand this body is sent to client on request. Replace placeholders with meaning values. Now you can start mock service with green arrow and it begins listening on port set before.

Get back to client side soapUI. You still have Request1 body opened. Click on URL in header and add new one: http://localhost:8088/mockWeatherForecastSoap - you may want to change port ot path, depend on you previous settings.
After setting up new url you can run client request again. If everything is ok, you will see Response1 body as a result of your operation.

Now you have both client and server with the same wsdl and option to organize conversation between them. Of course, in real life there is no sense in this matter, either server or client should be real systems. But for learning purposes this is good and hope it will help you to develop you web services in more optimized way.




         romanenco.com 2008