jojo
jojo

Reputation: 13843

how to generate web service client dynamically

i got a problem.

suppose on the other side, the WSDL will be always changed,

for example, the web service on the otherside which descriped in the WSDL file has only method, but the name of the method might always change, today call methodABC(), tomorrow will be change to methodDEFO()..

suppose in JAVA, is there anyway, i can dynamically generate the web service client, without manually do it by hand??? i mean dynamically generate the client when my application is still running..

or what kind of article should i go and have a look, coz i do a lots of search from the internet, cannot find a way to do it..i think i might need to create my own framework to handle it..but don`t know where to start.

Upvotes: 2

Views: 3681

Answers (4)

KB22
KB22

Reputation: 6969

Well,

there's a couple of questions to ask about this one:

1.: Does you application 'know' the actual i.e. the changed name of the method at runtime?

2.: Are you in control of that web service?

3.: What framework do you use for the WS communication?

Upvotes: 0

skaffman
skaffman

Reputation: 403501

Web services of this sort where the WSDL changes dynamically are not suitable for generated client bindings.

Most web service stacks support the concept of a dynamic clients, where you invoke the web service operations in a less static way.

To pick one example, see the relevant part of the Apache CXF dopcumentation.

Another example, is Spring-WS, which never uses WSDL-generated code, but instead is XML document-centric. If you have highly changeable web services, then I would strongly recommend Spring-WS over the more "traditional" JAX-WS generated client.

Upvotes: 0

gustafc
gustafc

Reputation: 28865

You can use any WSDL-to-Java tool in conjunction with the Java Compiler API, load the generated classes with a URLClassLoader, and get going. Quite a bit of work, but not very hard, I'd say. (You may run out of permgen space eventually, though.)

However, if your scenario is reality, the most important question would not be how to generate the classes, but why is the publisher of the web service on crack?

Edit: To clarify the "on crack" thingie. Changing the interface of the web service (e.g., a method name) means that you'll have to guess which method to call. If there's only one method in the interface, it is admittedly not that hard to figure out which method to call, but still - what happens if suddenly TWO methods pop up in there?

Changing the interface of a service used by external systems is a Really Big Thing, and should not be taken lightly. It should most definitely be automated. It is one heck of a code smell, and most likely a sign of incompetence, substance abuse and/or sheer insanity.

I realize my moralizing like this doesn't solve your problem. I just hope you can talk someone responsible into understanding that a web service constantly changing its interface is, well, an abomination, and that it would be better to have that changed, than adapting your code to it.

Upvotes: 8

Kalpak
Kalpak

Reputation: 3530

Generally wsdl is the file which is like a contract between the consumer and the host. If that is going to change dynamically, you need to understand the repurcussions of this change than dynamically consuming the service.

Upvotes: -1

Related Questions