How to change webservice url endpoint?
Solution 1
IMO, the provider is telling you to change the service endpoint (i.e. where to reach the web service), not the client endpoint (I don't understand what this could be). To change the service endpoint, you basically have two options.
Use the Binding Provider to set the endpoint URL
The first option is to change the BindingProvider.ENDPOINT_ADDRESS_PROPERTY
property value of the BindingProvider
(every proxy implements javax.xml.ws.BindingProvider
interface):
...
EchoService service = new EchoService();
Echo port = service.getEchoPort();
/* Set NEW Endpoint Location */
String endpointURL = "http://NEW_ENDPOINT_URL";
BindingProvider bp = (BindingProvider)port;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
System.out.println("Server said: " + echo.echo(args[0]));
...
The drawback is that this only works when the original WSDL is still accessible. Not recommended.
Use the WSDL to get the endpoint URL
The second option is to get the endpoint URL from the WSDL.
...
URL newEndpoint = new URL("NEW_ENDPOINT_URL");
QName qname = new QName("http://ws.mycompany.tld","EchoService");
EchoService service = new EchoService(newEndpoint, qname);
Echo port = service.getEchoPort();
System.out.println("Server said: " + echo.echo(args[0]));
...
Solution 2
To add some clarification here, when you create your service, the service class uses the default 'wsdlLocation', which was inserted into it when the class was built from the wsdl. So if you have a service class called SomeService, and you create an instance like this:
SomeService someService = new SomeService();
If you look inside SomeService, you will see that the constructor looks like this:
public SomeService() {
super(__getWsdlLocation(), SOMESERVICE_QNAME);
}
So if you want it to point to another URL, you just use the constructor that takes a URL argument (there are 6 constructors for setting qname and features as well). For example, if you have set up a local TCP/IP monitor that is listening on port 9999, and you want to redirect to that URL:
URL newWsdlLocation = new URL("http://theServerName:9999/somePath");
SomeService someService = new SomeService(newWsdlLocation);
and that will call this constructor inside the service:
public SomeService(URL wsdlLocation) {
super(wsdlLocation, SOMESERVICE_QNAME);
}
Solution 3
I wouldn't go so far as @Femi to change the existing address property. You can add new services to the definitions section easily.
<wsdl:service name="serviceMethodName_2">
<wsdl:port binding="tns:serviceMethodNameSoapBinding" name="serviceMethodName">
<soap:address location="http://new_end_point_adress"/>
</wsdl:port>
</wsdl:service>
This doesn't require a recompile of the WSDL to Java and making updates isn't any more difficult than if you used the BindingProvider option (which didn't work for me btw).
Related videos on Youtube
EugeneP
I am a Java developer. Feel free to send me a letter Need some help from experienced developers on personal growth and mastering Java. Would love to hear from you. Eugene [email protected]
Updated on July 08, 2022Comments
-
EugeneP almost 2 years
I generated a web-service client using JBoss utils (JAX-WS compatible) using Eclipse 'web service client from a wsdl'.
So, the only thing I provided was a url to a web-service WSDL.
Now, the web service provider tells me to change the "url of client endpoint application access" of the web-service.
What is it and how to change it?
-
hansvb about 14 yearsCan you just recreate the thing using the same Eclipse wizard with the new URL?
-
systempuntoout about 14 yearsTell web service provider you need the new url to wsdl, then use it with Eclipse wizard to regenerate the client.
-
EugeneP about 14 years@Thilo @systemputoout GUYS, the problem is that they have THE SAME WSDL URL !! I'm not sure, but it seems to me that in Axis you can provide a URL when invoking the web service. In JAX-WS you cannot change the "client endpoint during runtime". Any ideas, guys?
-
Devanshu Mevada about 14 yearsI must be missing something then and will remove my answer (I don't understand what the "client endpoint" is, it doesn't make any sense to me).
-
EugeneP about 14 years@ Pascal Thivent, @systempuntoout Cite: "URL or endpoint for client application access"
-
Devanshu Mevada about 14 yearsWell, my understanding of this sentence is "clients access a service endpoint; the endpoint location has changed". And this makes sense.
-
-
Jaime Hablutzel about 12 yearsI think that there is an error in the second code block, shouldn't it be URL newEndpoint = new URL("WSDL_URL"); in the first line ??
-
Myobis over 10 yearsIn many cases, the WSDL is imposed to you and you are not supposed to change it. More importantly, from an environment to another (test vs live), the endpoint url is likely to change.. and nobody wants to tweak the wsdl and recompile in this case.
-
shareef about 8 yearshere is a link to a tutorial tugdualgrall.blogspot.com/2009/02/…
-
Christopher Schultz almost 8 yearsIt's worth pointing-out that modern
wsimport
tools do not generate code with aget[Service]Port
method any more. Instead, callget[Service]
and cast the resulting object to aBindingProvider
to set these kinds of properties. -
Cuga almost 8 yearsThanks @ChristopherSchultz on the wsimport tip! That def. worked for us
-
luis.espinal over 7 yearsNot necessarily. I have services generated with Apache CXF's wsdl2java, and even when we pass the new wsdl location to the constructor, its ports still attempt to bind to the location set at compile/generation time (not leaving any choice but to typecast the port to BindingProvider and set the new address in its request context map.)
-
MattC over 7 years@Luis - Hard to know exactly what you are seeing, but if you debug you should see the call into the javax Provider class, and then see it try to create the endpoint with your new wsdl location (assuming you are using JAX-WS 2.0+). Then inside your service, the getPort call should call super.getPort, which uses has your new port set in a serviceDelegate object. That's how it should work with javax.xml.ws.Service in JAX-WS 2.0. I'd put a breakpoint on the super call and investigate from there.
-
Markus L over 7 yearsThe first method is interesting! I'm using
Service service = Service.create(soapUrl, qName)
to create a web service and then I can callgetPort(..)
on it. However, when I use the default constructor of the web service there is no method likegetPort(..)
which I could use! How do you do this? How does yourEchoService
look like? -
cacert over 7 yearsAs far as I understand from cxf generated stub code, the second option above changes wsdl url, not the service url. Am i missing something?
-
havoc1 almost 6 yearsThanks @ChristopherSchultz for the clarification. In my impl I couldn't figure out what get[Service]Port() referred to.
-
Venkat over 3 years@MattC - Whether the WSDL URL we add to the project always needs to be accessible even if we change the URL dynamically? Could you please share the behavior?
-
Kamil Bęben almost 3 yearsThe workaround for the first method to work all the time is to set
location
property of theaddress
tag in the wsdl tolocalhost
- it won't throw any errors. It is still useful in a few cases; ie, i need to access the wsdl from project resources, because of 'requirements' and still need to customize the address because there are multiple environments (test, prod, etc) -
Erikson Rodriguez almost 3 yearsmy client is deployed from other server, that's the razon to try set endpoint in other domain or dynacmically, but dont work only take the port but but not the domain