Saturday, June 28, 2014

Create a SOAP client from a WSDL with Eclipse or Microsoft Visual Studio


Supposed we have the WSDL file of an existing web service from which we want to create a SOAP client for testing purpose, both Eclipse and Microsoft Visual Studio can help us build one quickly. The WSDL file can be on the web or on the local disk.

Its URLs could look like the following:
   file:///c://path/to/the-wsdl-file.wsdl
   http://www.example.com/path/to/the-wsdl-file.wsdl

Create a SOAP client in Java with Eclipse

  1. Create an empty Dynamic Web Project (New->Projects...->Web->Dynamic Web Project).
  2. Right click on the project and select New->Others.
  3. In the "Select a wizard" dialogue, select Web Service->Web Service Client, and click the "Next" button.
  4. Input the URL of the web service in the Service definition box.
  5. Drag the slider on the left to choose to generate a Test client. Click the "Next" button.
  6. Follow the prompts to create the client and start Tomcat.
  7. A web-based test client is generated and we can run a test with it.
An alternative way (if using Linux) is:
  1. Create an empty Java Project.
  2. Use wsimport to generate the library for the WSDL, e.g.: wsimport -keep -verbose -d /path/to/eclipse/workspace/project/src /path/to/wsdl-file
  3. Write the source code for the test client using the generated library.

Create a SOAP client in C# with Microsoft Visual Studio

  1. Click on menu File->New Project...
  2. In the "New Project" dialogue, choose the template C#->Test. Change Name/Location/Solution/Solution name as needed. Click the "OK" button.
  3. On the Solution Explorer panel, right click on the project's References and select Add Service References...
  4. Input the URL of the web service in the Address box and click the "GO" button. Change the Namespace as needed. Click on the "OK" button.
  5. The test client is generated and the file UnitTest1.cs file is opened for us to add our test cases.
  6. Use http://www.webservicex.net/stockquote.asmx?WSDL as an example, We can write something like the below in TestMethod1():
ServiceReference1.StockQuoteSoapClient client = new ServiceReference1.StockQuoteSoapClient("StockQuoteSoap");

String quote = client.GetQuote("AAPL"); 

Create a SOAP client in VB with Microsoft Visual Studio

  1. Click on menu File->New Project...
  2.  In the "New Project" dialogue, choose the template Visual Basic->Test. Change Name/Location/solution/solution name as needed. Click the "OK" button.
  3. On the Solution Explorer panel, right click on the project's name and select Add Service References...
  4. Input the URL of the web service in the Address box and click the "GO" button. Change the Namespace as needed. Click on the "OK" button.
  5. The test client is generated and the file UnitTest1.vb file is opened for us to add our test cases.
  6. Use http://www.webservicex.net/stockquote.asmx?WSDL as an example, We can write something like the below in TestMethod1():
Dim client As New ServiceReference1("StockQuoteSoap")
Dim quote As String

quote = client.GetQuote("AAPL")

No comments:

 
Get This <