File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Creating a client to consume a webservice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Creating a client to consume a webservice" Watch "Creating a client to consume a webservice" New topic
Author

Creating a client to consume a webservice

Mark Tobin
Ranch Hand

Joined: May 05, 2010
Posts: 37
Hi

I have a webservice

@WebMethod(operationName = "SendMessage")
@WebResult(name = "messages")
public Messages sendMessage(request message) throws WebServiceException;

I want to create a client that will call sendMessage.

In RMI you generate a stub that the client can import. That way the client knows the method name an parameters of the service endpoint

Working of this tutorial

http://72.5.124.55/javaee/5/docs/tutorial/doc/bnayn.html

client HelloClient wants to call a service HelloService

in the client we have

import helloservice.endpoint.HelloService;


The client imports the service endpoints, which I guess is a stub. But the tutorial has missed out the step on how to create the stub.

Is there a link that explains how to create the service stub so that the client can import it.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39530
    
  27
You'd use the wsgen tool that's mentioned on that page; there's also a link that points to further documentation on that.


Ping & DNS - updated with new look and Ping home screen widget
Mark Tobin
Ranch Hand

Joined: May 05, 2010
Posts: 37
Hi ulf

Having problems geeting wsgen to work

My service interface is MessageService

@WebService(targetNamespace = "http://ws.serviceApp.com/messageservice", name = "MessageService")
@SOAPBinding(style = Style.DOCUMENT, parameterStyle = ParameterStyle.BARE, use = Use.LITERAL)
public interface MessageSubmissionService {

@WebMethod(operationName = "SendMessage")
@WebResult(name = "messages")
public WsMessages sendMessage(WsRequest messages) throws WebServiceException;

I am trying to call wsgen this way

wsgen -classpath C:\workspace\serviceApp\webservice\service -servicename http://ws.serviceapp.com/service/MessageService.java

Not sure what I am doing wrong

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39530
    
  27
Maybe this helps: http://java.sun.com/javase/6/docs/technotes/tools/share/wsgen.html

It says to use the "servicename" parameter only in conjunction with the "wsdl" parameter.
Mark Tobin
Ranch Hand

Joined: May 05, 2010
Posts: 37
Hi ulf

I am calling wsgen this way now

wsgen -d C:\tmp -classpath serviceApp.webservice.service.MessageService.java

still not able to create the client wrapper I get an error

Missing SEI

MessageService.java is my ServiceEndPointInterface

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39530
    
  27
"serviceApp.webservice.service.MessageService.java" is not a classpath, so that doesn't make sense. It's also not a file ("serviceApp/webservice/service/MessageService.java " would be) so it couldn't serve as the SEI.
Mark Tobin
Ranch Hand

Joined: May 05, 2010
Posts: 37
Sorry ulf

Really confused now.

Looking at the example

wsgen -cp . example.Stock

example is the classpath an Stock the Service End Point Interface, is that not right


which is why I tried -d C:\tmp -classpath serviceApp.webservice.service.MessageService.java an get the Missing SEI error

I have also used the full path

wsgen -cp C:\workspace\serviceApp\webservice\serviceMessageSubmissionService.java I still get the Missing SEI error.

Not sure what other combinations I should use. I have given it the path an the file that contains the annotations @WebService not sure what else I should be setting
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39530
    
  27
wsgen -cp . example.Stock

example is the classpath an Stock the Service End Point Interface, is that not right

No, it's not. The classpath is ".", and the SEI is "example.Stock"

Note that the SEI must be a classname (not a file name), so it wouldn't end in ".java".

Classpath and SEI are two separate parameters that can't be mixed.
Mark Tobin
Ranch Hand

Joined: May 05, 2010
Posts: 37
Got it

I have to point at my classes directory not my java

I run wsgen -cp . serviceApp.webservice.service.MessageServiceImpl


For any one else also new to this, you have to run it against the MessageServiceImpl if you run it against the interface MessageService you will get the following error

The class "serviceApp.webservice.service.MessageService" is not an endpoint implementation class.

Thanks Ulf for all your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a client to consume a webservice
 
Similar Threads
STUB, Dynamic Proxy, DII
ClassCastException in J2ME web service client.
how to consume a webservice using axis2
WebService Call Failed
JAX-RPC client side programming