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.