No one has any ideas on this?
Right now it looks like my options are either a) the client must fetch the WSDL every single time it makes a request, or b) the server's URL must be hard-coded in the WSDL file that is bundled with the client.
Neither of these are good. There's no reason at all for the client to keep on fetching the WSDL. If the WSDL were to change, the client wouldn't be able to work with it, because it wouldn't be able to process the interaction. So there's really no point in a client fetching the WSDL. But I don't want to hard-code the server URL in the bundled WSDL either.
Did Sun just not think of this? Imagine a client which makes frequent requests, like a chat client for example. This might make requests once per second or more. Did they really think that it would be good to keep on fetching the same WSDL over the net, once per second, when that file can never even change? The bandwidth on this hypothetical chat client would consist about 99% of the same WSDL transmitted over and over, and about 1% actual data.
I must be missing something. Can this possibly be correct?
You can always set the url in the service object when adding the port, like the following:
Service service = Service.create(new QName("...", "...")); service.addPort(new QName("...", "..."), SOAPBinding.SOAP11HTTP_BINDING, "http://service.location/at/some/context"); dispatch = service.createDispatch(new QName(...","..."), SOAPMessage.class, Service.Mode.MESSAGE);
Thanks for the suggestion. I tried that. After doing it that way, I had the problem of needing to use JAXB to put my parameters into the SOAPBody. That worked, but then I got unsolvable class conflicts where I got to this:
[java] Exception in thread "main" com.sun.xml.ws.streaming.XMLStreamReaderException: XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1] [java] Message: Premature end of file. [java] at com.sun.xml.ws.streaming.XMLStreamReaderUtil.wrapException(XMLStreamReaderUtil.java:256) [java] at com.sun.xml.ws.streaming.XMLStreamReaderUtil.next(XMLStreamReaderUtil.java:84) .... [java] Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1] [java] Message: Premature end of file. [java] at com.sun.xml.stream.XMLReaderImpl.next(XMLReaderImpl.java:563) [java] at com.sun.xml.ws.util.xml.XMLStreamReaderFilter.next(XMLStreamReaderFilter.java:92)
What's strange is that the message went through just fine. The server read it and parsed it with no errors. But the client gave me that error. I had been hoping that SOAP would do all the marshaling / unmarshaling for me, without me needing to invoke JAXB stuff, but apparently it doesn't, and there doesn't seem to be a way of solving that XML parsing exception. This is all in Java 6.
Then I looked back at http://jbws.dyndns.org/mediawiki/index.php?title=JBossWS_JAX-WS_Tools and there is some suggestion to do this:
/* Set NEW Endpoint Location */ String endpointURL = "http://NEW_ENDPOINT_URL"; BindingProvider bp = (BindingProvider)echo; bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
And that works! I use wsclient.sh. No problems. I'm sure I can take the wsclient.sh and turn that into a script to execute my client.
I think that was added to that info about endpointURL page within the past couple of days because I didn't see it there last week.
Anyway... so I'm now happily able to use the JBossWS libraries on the client side, and specify a URL at run-time, without having to re-fetch the WSDL with every single request. So that's good.
The next thorny question: What if I want to add some attachments to my messages? In particular I want to send some image files, etc, with the SOAP message. Is there a way to do that?
I could go back to generating the SOAPMessage as above, but then I'll run into the same class loader hell that I couldn't solve before. Unless someone has solved that, I need to figure out some other way.
The alternative to all this is to write my own SOAP library, which might be less effort than figuring out how to resolve the class file conflicts in JBossWS + Java 6. But if someone knows how to solve some of these things, then that will be easiest.
Thanks for any suggestions.
Attachments are a tricky part. The simplest way to do is to add your attachment as a base64binary in your schema, but that is not what you always want to do. I've been asking a lot about how to use MTOM on a SOAPMessage, but I didn't get any response at all.
To answer your question about how to add attachments to a SOAPMessage. You have to add an AttachmentPart to your SOAPMessage. The JavaDoc describes this part pretty well. take a look at http://java.sun.com/javase/6/docs/api/javax/xml/soap/AttachmentPart.html.
Hope it helps!