I have a requirement to mock webservice call. Here instead of actual webservice call to dummy server and server should reply my response xml response file from local directory.
2 Answers
Our project used that approach (used for mocking external Webservices which were not available on local workspace).
Short answer is yes, but how to implement would depend on your code.
First , we created a interface to call webservice, so that we can create 2 implementations, one actual( which calls external service) and one Test ( which calls an internal WebService which reads from file).
Next, we created a test webservice which we hosted on the same server. Now the logic was simple. Based on input , we used to read the correct response from file. You can build whatever logic you want, our framework was designed to support multiple webservices. Lastly, in our code, kind of like spring, we used to point to test service ( via interface) instead of actual service. So we could read from file and provide a response. When external interface was available, we would simply switch the configuration and we were good.
Ofcourse, this is over simplification, but I hope you get the gist.

- 670
- 4
- 10
You have two ways of proceeding :
- mock the ws from the client side by providing an mocked implementation of the client ws.
- mock the the ws from the server side by creating a mocking instance of the ws.
Mocking the call from the client side is simple. You create an common interface with the ws methods you want to call. And you create two implementations of this. One with the effective call to the ws and another with stubbed responses coming from local files.
Mocking or simulating the ws from the server side is not much complicated but it is not the same approach. You can hard code it but it is not a secure solution when you must mock it again. You also can use a webservice simulator instead of your webservice. You will not query you webservice but another.
SOAPUi can help you to achieve this task by mocking your webservice responses.
Example for SOAP mocking
To use a local file as response, you should use SOAPUI response scripting.
SOAP reponse mocking

- 125,838
- 23
- 214
- 215