How to change the endpoint address in the existing generated webservice stub in NetBeans

Source: Internet
Author: User
Tags stub netbeans wsdl

It is very convenient to develop webservice with NetBeans, of course, the JDK6 environment is the best, but one problem often puzzles us, that is, when the code that is completed in the test environment or development environment is deployed to other machines, we will be helpless, Have to change the code of the target endpoint address; some people say that with the configuration file Ah, oh, in the pure manual write axis or xfire may be very convenient, but in NetBeans these automatically generated fragments, the change is more troublesome, although the development of the pull is very convenient. In the past, I have always been so comfort myself, things have two sides. Recently saw the Sun WebService eldest brother Arun Gupta article, found that in fact to change this is very easy, very easy, but there are problems, the following will be detailed.

For example:
by Arun, the WSDL we often use generates code to invoke WebService, where JAX-WS version is 2.1
Hello port = new HelloService (). Gethelloport ();
String result = Port.sayhello ("duke!");
Of course, the description above is a webservice that corresponds to a specific IP address, and if the same service is eventually deployed to another machine, it cannot be used. So, we can add another line of code between the two lines above:
((Javax.xml.ws.BindingProvider) port). Getrequestcontext (). Put ( Javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "New_address_here");
You can simply replace the new_address_here with the appropriate endpoint address in the actual use.

I think Arun in the test and I was made the same mistake, after changing the endpoint, if the above method, the original app server is not closed when it is feasible, but this situation rarely occurs. In the execution "Hello port = new HelloService (). Gethelloport ();" This code will first fetch the original WSDL file, and if the original app server is closed, it will report an exception ((Javax.xml.ws.BindingProvider) port). Getrequestcontext (). Put ( Javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "New_address_here"); This code cannot be executed again.

After groping, I found a good way, specifically as follows:

First, to define the new endpoint Url:url endpoint_new = the URL ("New_address_here");

Redefine a qname:qname QName = new QName ("http://" + "Original_package", "service_name");

Where New_address_here is the new endpoint address, Original_package is the resulting webservice package, Service_Name is the name of the SERVICE issued, try to know that if you fill in the wrong, Will prompt you what is the effective writing.

Finally, hello port = new HelloService (). Gethelloport (); This sentence is replaced, and changed to Hello port = new HelloService (endpoint_new,qname). Gethelloport ();

I found another article at JAX-WS website: https://jax-ws.dev.java.net/guide/How_to_invoke_and_endpoint_by_overriding_endpoint_ Address_in_the_wsdl.html. It has included both of the above, but not how to specify, let a person a bit puzzled.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.