How to dynamically generate a web service client

I have a problem.

suppose on the other hand the WSDL will always change,

for example, the web service on the other hand, which is described in the WSDL file, only has a method, but the method name can always change, today the call to the ABC () method, tomorrow will change to the DEFO () method ..

suppose in JAVA, anyway, I can dynamically generate a web service client, without having to do it manually? I mean dynamically creating a client when my application is still running.

or what article should I go and see because I do a lot of searching from the internet, can't find a way to do this. I think I might need to create my own infrastructure to handle it. but you don't know where to start.

+2


source to share


4 answers


You can use any WSDL-to-Java tool in combination with the Java Compiler API , load the generated classes with URLClassLoader , and continue. I would say a little work, but not very difficult. (Ultimately, however, you may escape from pergene space.)

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 cracked?

Edit: To clarify the "on the crack" topic. Changing the interface of the web service (such as the name of the method) means you have to guess which method to call. If there is only one method in an interface, then, admittedly, it is not that difficult to determine which method to call, but still - what happens if TWO methods suddenly appear there?



Changing the interface of a service used by external systems is a really big thing and shouldn't be taken lightly. It should definitely be automated. This is one of the traits of code smell and is most likely a sign of incompetence, substance abuse and / or sheer insanity.

I understand that my moralizing like this does not solve your problem. I just hope you can talk to someone in charge, realizing that a web service that constantly changes its interface is probably an abomination, and that it would be better if this changed than adapting your code to it. ...

+7


source


Well,

there are several questions to ask about this:

1: Does the application "know" the actual, that is, changed method name at runtime?



2: Do you control this web service?

3: What structure do you use for WS communication?

0


source


This type of web service that dynamically changes the WSDL is not suitable for generated client bindings.

Most web service stacks support the concept of dynamic clients where you call web service operations less statically.

For a selection of one example, see the relevant section of the Apache CXF dopcumentation .

Another example is Spring-WS, which never uses WSDL generated code, but is instead XML oriented document. If you have heavily modified web services, I would highly recommend Spring-WS for the more "traditional" JAX-WS generated client.

0


source


Typically wsdl is a file that looks like a contract between consumer and host. If this changes dynamically, you need to understand that this change has changed rather than dynamically consume the service.

-1


source







All Articles