Igor
Igor

Reputation: 1464

How to create a java client that consumes a webservice?

Well, I've created a webservice that i can find accessing locally at:

http://127.0.0.1:8080/myapp/WSPA?wsdl

Now i need to test my webservice by calling it from another java application to verify it its working fine. I've seen that its working using WebService Client from JBoss plugin on eclipse. But the problem is that i have a method wich recieves a list of SoapFile containing a String and array of bytes. And i need to verify if its working.

@XmlType
public class SoapFile implements Serializable {

  private String fileName;
  private byte[] fileData;

  public String getFileName() {
     return fileName;
  }

  public void setFileName(String fileName) {
     this.fileName = fileName;
  }

  public byte[] getFileData() {
     return fileData;
  }

  public void setFileData(byte[] fileData) {
     this.fileData = fileData;
  }
}

I've not found how to create a simple webservice client that consumes that service to test. I would like some direction for this... Tutorial or some website that explains how to make it step by step. How can i create a java client for this webservice?

Upvotes: 2

Views: 5400

Answers (3)

Tim
Tim

Reputation: 643

A "Hello World" Tutorial with wsimport for Jax-WS can you find here

Tim

Upvotes: 0

Alankar Srivastava
Alankar Srivastava

Reputation: 864

Do you have a WSDL file. If yes then you can use IDE like eclipse to generate client stub.

Below link will also be a good place to start

http://docs.oracle.com/cd/E17802_01/webservices/webservices/reference/tutorials/wsit/doc/Examples_glassfish6.html

Upvotes: 1

Michał Kupisiński
Michał Kupisiński

Reputation: 3863

Igor, just use wsimport with your web service url - you will get generated classes for WebService and then just invoke service in that way:

ServiceGenerateFromWSImportWhichIsTheSameAsYour iService = 
   new ServiceGenerateFromWSImportWhichIsTheSameAsYour().
            getServiceGenerateFromWSImportWhichIsTheSameAsYourPort();

// now on iServie instance you can invoke method from your webservice
// but you have to use stub classes generated by wsimport

iService.myMethodWhichGetFileList(List<SoapFileStubGeneratedClass> sopaFiles);

And wsimport is standard java tool in jdk instal folder

More on wsimport tool you can find here:

wsimport doc

Using wsimport in your case will be:

wsimport -p generated_classes -s generated_sources http://127.0.0.1:8080/myapp/WSPA?wsdl

and you will find .class files in folder generated_classes and .java files in folder generated-sources

Upvotes: 2

Related Questions