aspose file tools*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes use jaxws:binding to change a name of a web method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "use jaxws:binding to change a name of a web method" Watch "use jaxws:binding to change a name of a web method" New topic
Author

use jaxws:binding to change a name of a web method

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 812
    
    1
Hi, ranchers,
I can use this external binding to change a webmethod hellWorld into HiWorld

I can use the wsdl to generate a client code. The client can call the HiWorld method. However, the server has helloWorld method instead. I got a no class definition found error.

So, what should I do?
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1733
    
  25

What is your WSDL and how do you generate the client code?

Regards,
Frits
Noni Singh
Greenhorn

Joined: Feb 09, 2011
Posts: 20
Using external binding to change method name while generating client code will be reflected in generated SEI, but will retain the original method name in @WebMethod(operationName="") which will be on the method of generated SEI.

Invoking Web Service w/ altered method name (at client) shouldn't be a issue as @WebMethod(operationName="") value is used when generating SOAP message.

Changing operationName value on generated SEI will cause invocation failure, with exception similar as below:
javax.xml.ws.WebServiceException: Method xyz is exposed as WebMethod, but there is no corresponding wsdl operation with name xyz



Regards,
Noni


OCP JSE 5 Programmer, OCE JPAD, OCE WSD6
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 812
    
    1
Suppose I have this :


I deployed the SEI and SBI on Tomcat. The WSDL has helloWorld as the operation node in portType node.
Suppose the WSDL is at http://localhost:8080/example/helloworld?wsdl

I generated the client code using wsimport -keep -p client http://localhost:8080/example/helloworld?wsdl -b external.xml , where external.xml is the file with the bindings in my previous post.
And so on the client code, I invoke hiWorld instead of helloWorld.
But I got a no class definition exception. I guess the reason is on the client code, it has hiWorld method, but the operation is helloWorld.
Noni Singh
Greenhorn

Joined: Feb 09, 2011
Posts: 20
Is your request reaching the server? I mean, is the exception raised by client before sending request or server?

If reaching the server, could you check the SOAP request message which is getting generated. Per my understanding, it should have <helloWorld> instead of <hiWorld> as body part.

Can you try again, by generating client from same WSDL but w/o external binding as "no class definition exception" is for missing class.

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 812
    
    1
I tired it without -b external.xml. It worked.
But the server side does not generate any error message. On the client side, it throws the no class definition found exception. So, obviously, the the request has not reached the server yet.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1733
    
  25

How does your client code look like and can you post a bit of the exception stack trace?
Noni Singh
Greenhorn

Joined: Feb 09, 2011
Posts: 20
Which parameterStyle in @SOAPBinding annotation, WRAPPED (default) or BARE, you've on the SEI?
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 812
    
    1
Thanks for your help. I tried with my homework as a practical example:


The WSDL (only relevant part shown):


//external binding file, changeName.xml




//The SEI from the client side after the changeName.xml is used
public interface OrderServiceWS{

@WebMethod(operationName = "catalogue")
@WebResult(targetNamespace = "")
@RequestWrapper(localName = "catalogue", targetNamespace = "http://...", className = "hw4Client.Catalogue")
@ResponseWrapper(localName = "catalogueResponse", targetNamespace = "http://...", className = "hw4Client.CatalogueResponse")
public hw4Client.CatalogueResponse.Return shopCatalogue();

}
[/code]

Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1733
    
  25


@WebServiceRef(wsdlLocation="http://localhost:8080/inventoryWS/ws/OrderServiceHw4?wsdl")
private static OrderService service;
private static OrderServiceWS port;
service = new OrderService();
port = service.getOrderPort();
port.shopCatalogue();

You are injecting the OrderService instance in your client (is you client a Servlet, or an EJB, or a POJO?) in to the "service" field.

What I don't get is why you create a new Service instance ( service = new OrderService() )?

Regards,
Frits
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 812
    
    1
The web service is deployed as a Servlet on Tomcat.

The wsimport generates the OrderService , OrderServiceWS and other artifacts from the WSDL on the client side. The client can use an instance of OrderService to invoke the service deployed on Tomcat.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1733
    
  25

but you still haven't answered my 2 questions.
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 812
    
    1
To answer your second question:
The wsimport generates OrderService interface and OrderServiceWS class from the WSDL. So, the client creates an instance of OrderService to invoke the web methods.
In Java Web Service Up and Running by Martin Kalin, in Chapter 1-2, there are example like that.

Here is another example:
http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/

In the HelloWorldClient example, an instance of Service, HelloWorldImpService is created to call the web method.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1733
    
  25

so why are you injecting the service with the webserviceref?
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 812
    
    1
This is part of my OrderService from the client:


My instructor provides the @WebServiceRef (....) to inject the WSDL.
I am sure it still works without the @WebServiceRef (...)
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 812
    
    1
I look at an example from :
http://docs.oracle.com/javaee/6/tutorial/doc/bnayn.html

It also inject the WSDL by using @WebServiceRef(wsdlLocation=...)
I see your point now.
If I inject the service by @WebServiceRef, I don't even need to create an instance.

In my case,
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1733
    
  25

I see your point now.
If I inject the service by @WebServiceRef, I don't even need to create an instance.

Exactly

When you remove the @WebServiceRef, do you still get the exception?

Can you post a bit of the stacktrace?

Regards,
Frits
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 812
    
    1
Experiment 1:

It works
But ...
Noni Singh
Greenhorn

Joined: Feb 09, 2011
Posts: 20
Per JAX-WS 2.2 spec - "The WebServiceRef annotation is required to be honored when running on the Java EE 5 platform, where it is subject to the common resource
injection rules described by the platform specification [35]."


@WebServiceRef will work with JAX-WS managed clients: Servlet, EJB, or another Web service.

You client code looks like standalone java client and that's why the annotation is not working and service is null.


Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1733
    
  25

You client code looks like standalone java client and that's why the annotation is not working and service is null.

Correct!

Regards,
Frits
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: use jaxws:binding to change a name of a web method