• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to point generated client to new webserver?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I used Netbeans 6.1 to generate a Java client from a web service wsdl. The web service runs on my laptop at http://localhost, and the new Java client works great with it. The client runs this code to invoke the service (HelloWorld):

org.tempuri.Service sv = new org.tempuri.Service();
org.tempuri.ServiceSoap ss = sv.getServiceSoap();
String result = ss.helloWorld();

Here's the problem: when I eventually put my web service on a real web server, how will I programmatically point my new client to the new URL?

Apologies if this question has been answered before, but I haven't found it yet.

Thanks if you can help,
John (First time poster)
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

If my understanding is correct you are expected to generate the client stub as the application that uses it is deployed to the production server as the WSDL that is being used actually contains the endpoint's URL (i.e. the address is part of a larger external dependency to your application rather than some application specific configuration detail). It is therefore is imperative to capture the client side specifics like target package name etc. in the deployment script. If you take a look at the source of the generated client stub you will see that the stub actually accesses the WSDL to obtain the endpoint URL during runtime - so once deployed a change in endpoint address shouldn't be a problem as long as the WSDL doesn't move. You can programmatically change the WSDL location however by using the javax.xml.ws.Service.create(java.net.URL,javax.xml.namespace.QName) static method.

By the way: dump that tempuri.org as soon as possible. It literally means "temporary URI" that should be replaced immediately with a real unique URI - otherwise whatever you do is in danger of colliding with all the other stuff that was silly enough to use leave tempuri.org. See here.
[ November 17, 2008: Message edited by: Peer Reynders ]
 
John Atkeson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
----------------------------
so once deployed a change in endpoint address shouldn't be a problem as long as the WSDL doesn't move.
You can programmatically change the WSDL location however by using the
javax.xml.ws.Service.create(java.net.URL,javax.xml.namespace.QName) static method.
----------------------------

So changing the WSDL location this way points the client to a different web service URL too, right?

Hmm, I tried the static create method with this code:

javax.xml.ws.Service factoryTest = javax.xml.ws.Service.create(
new URL("http://localhost:28451/Stenographer/Service.asmx?wsdl"),
new javax.xml.namespace.QName("http://localhost:28451/Stenographer/Service.asmx/", "HelloWorld"));

Debugging/stepping through, it throws this error:
{http://localhost:28451/Stenographer/Service.asmx/}HelloWorld is not a valid service. Valid services are: {http://tempuri.org/}Service

The WSDL address is right, it's tried and tested, and HelloWorld is running as the service. What else might I be doing wrong?



----------------------------
By the way: dump that tempuri.org as soon as possible.
----------------------------

Absolutely; how do I do that?


Thanks for the advice, I just need to understand this a little better.
John
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Atkeson:

Debugging/stepping through, it throws this error:
{http://localhost:28451/Stenographer/Service.asmx/}HelloWorld is not a valid service. Valid services are: {http://tempuri.org/}Service

The WSDL address is right, it's tried and tested, and HelloWorld is running as the service. What else might I be doing wrong?



Good grief, it seems like the http://tempuri.org/ namespace was allowed to leak into the published WSDL (that namespace identifier is modifiable in Visual Studio as this is obviously a .NET web service) - seriously, removing http://tempuri.org/ needs to be a coding standard in every organization that dabbles with web services. NetBeans uses wsimport under the which allows you to specify a "p" or "package" option which forces the generated artifacts into a package of your choosing (instead of the default "reverse namespace identifier" package name).

I can't be of much help without looking at the WSDL. However service names are usually created in the targetnamesspace of the WSDL which seems to be "http://tempuri.org/", not "http://localhost:28451/Stenographer/Service.asmx/" as you specified (that is simply the endpoint address). Furthermore the error seems to suggest that the name in the WSDL {http://schemas.xmlsoap.org/wsdl/}service element isn't "HelloWorld" but "Service". If I'm correct that code should be:


Note that I also used the specialized org.tempuri.Service version which should allow you to access the a specialized Port object that will ultimately have the web method that you are after.
 
John Atkeson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I managed to get rid of tempuri.org from the namespace. It helps when you have access to the web service source code. ;-)

------------------------------------------
org.tempuri.Service factoryTest = org.tempuri.Service.create(
new URL("http://localhost:28451/Stenographer/Service.asmx?wsdl"),
new javax.xml.namespace.QName("http://tempuri.org/", "Service"));
------------------------------------------

I tried this and it didn't compile because org.tempuri.Service.create() still creates a javax.xml.ws.Service type. So then I cast it this way:

org.tempuri.Service factoryTest = (org.tempuri.Service)org.tempuri.Service.create(...);

But that crashed, saying it couldn't cast it as such.

More later, got a meeting...

Gracias.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic