• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to change WSDL url dynamically

 
Aj Maharaj
Greenhorn
Posts: 2
Firefox Browser MySQL Database Netscape
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to change WebServiceRef URL runtime specially IP(172.16.6.241) address only.
can any one help me

_______________________________________________________________

@WebServlet(name="ClientServlet", urlPatterns={"/ClientServlet"})
public class ClientServlet extends HttpServlet {
static long ReqCount = 1;
static int OldSec = 0;

@WebServiceRef(wsdlLocation="http://172.16.6.241:8080/CalculatorApp/CalculatorWSService?wsdl")

public CalculatorWSService service;

@Resource
protected WebServiceContext context;

___________________________________________________________________
 
Raghav Viswanathan
Greenhorn
Posts: 26
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Maharaj,

I assume that the question posed here is to dynamically choose the end point of the webservice.

The scenarios here is . Let us assume that I have a service which prints Hello world along with your name when invoked. The following would be the steps.
1. Deploy the service at end point A and end point B.
2. Use wsimport command to create the client files needed for invoking the service from any one of the end points.
3. use the following piece of code


URL url = new URL("http://localhost:9999/ws/SayHello?wsdl"); // Note you can change the URL here to call different endpoints which host the service
QName qname = new QName("http://ws.hellowservice.com/", "HelloWorldServiceImpl"); // refers to the TNS name and the service Name as given in the WSDL file

//1st argument service URI
//2nd argument is service name

Service service = Service.create(url, qname);

// Please note that you can also invoke create method whioch is overloaded with no argument. This will inturn use the endpoint that was used to generate the client files.

HelloWorldService helloWorldService = service.getPort(HelloWorldService.class);

System.out.println(helloWorldService.sayHello("Maharaj AJ"));

Hope this helps,... Do let me know if you still have doubts ... or if you would need any other implementations....

Thanks and regards
Raghav.V

 
Aj Maharaj
Greenhorn
Posts: 2
Firefox Browser MySQL Database Netscape
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Raghav
I will try This..in My Project

Raghav Viswanathan wrote:Hello Maharaj,

I assume that the question posed here is to dynamically choose the end point of the webservice.

The scenarios here is . Let us assume that I have a service which prints Hello world along with your name when invoked. The following would be the steps.
1. Deploy the service at end point A and end point B.
2. Use wsimport command to create the client files needed for invoking the service from any one of the end points.
3. use the following piece of code


URL url = new URL("http://localhost:9999/ws/SayHello?wsdl"); // Note you can change the URL here to call different endpoints which host the service
QName qname = new QName("http://ws.hellowservice.com/", "HelloWorldServiceImpl"); // refers to the TNS name and the service Name as given in the WSDL file

//1st argument service URI
//2nd argument is service name

Service service = Service.create(url, qname);

// Please note that you can also invoke create method whioch is overloaded with no argument. This will inturn use the endpoint that was used to generate the client files.

HelloWorldService helloWorldService = service.getPort(HelloWorldService.class);

System.out.println(helloWorldService.sayHello("Maharaj AJ"));

Hope this helps,... Do let me know if you still have doubts ... or if you would need any other implementations....

Thanks and regards
Raghav.V

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic