Please carry me if this sounds like a trivial question.
This is not a trivial question. What trivial are all the Hello World web service examples and tutorials you find on the Internet that never offer any tips on how to manage the Real World web services later.
Is this how we should change existing web services?
Well, not quite. I will try to give a general explanation and perhaps a possible solution for your specific case, so please tell me about me (: D), as this will be a long post.
Contract first and last contract
There are two approaches to creating web services: first a contract, and the last contract.
A contract first means creating a WSDL, and then generating Java code that implements the contract provided by WSDL. The last contract means creating your Java code and then creating code-based WSDL.
Both have advantages and disadvantages, but in both cases it is important to contract.
Contract
Your WSDL describes the contract. After deploying your web service, the contract should remain frozen. A contract is the basis for communication between a web service and its customers (don't even make me start with web service compatibility ).
The web service and all customers implement this contract in their code.
I made changes to WSDL ...
This is not always a good idea.
When a contract for a web service changes, users of the contract may break. When you change the WSDL, you restore the web service code to support the new contract. But what about customers?
If new modifications violate the contract, you will need to instruct all customers to receive a new contract and change your code to make changes. How many customers do you have for this web service? What changes did you make to WSDL?
Contract gap changes vs non-breaking changes
You can make some changes to the contract without breaking customers. For example, you can add a new operation. Clients do not know about this in their code, and what they do not know cannot harm them. You can also add some optional parameters to existing messages; since they are optional, this means that they can be omitted during communication and the client code is not aware of this, and what they do not know cannot harm them. These are inextricable changes.
Breaking change ... well ... breaking the contract. These include, for example, changing the names of operations, changing types or names of message parameters, adding required parameters, etc. Client code is now broken. Clients just found out about this (existing code no longer works) and they are injured. Your web service is no longer in use at this time.
What changes have you made to your WSDL?
Code
In the latest contract, the WSDL is created based on the web service code. This has the disadvantage that it associates a code implementation with WSDL. If you make changes to the code, you can initiate changes to the WSDL, so in the contract you agreed with your customers.
But if in the first approach to the contract you make changes to the WSDL and then restore the skeleton code of the web service, you will change the contract again. You haven’t done anything better ... and now you have another problem. What happens to the existing skeleton web service code that you now generate again?
Generating Code from WSDL
When you create the code from WSDL, you get the skeleton of the web service. This is boilerplate code that simply outputs your web service messages to the wire in the SOAP format specified in the contract.
Typically, you generate this code and include it in your project, which will be used by the “important” web service code, a code that actually provides the “service”. How you use this code is important. You should take into account the case of generating the code again later, without overwriting the existing code.
Typically, a code generation tool can split your skeleton code into an interface and an implementation of that interface. You must abandon the generated implementation and provide your own implementation of the interface , you provide your implementation elsewhere so that it does not overwrite when creating the skeleton code. Of course, if the interface changes, you will have problems with compilation, because it will not correspond to the new contract, but at least you have code to change it: D.
Unfortunately, this is not what happens in most projects. People change the generated implementation directly, and when they generate the skeleton again, they lose all their added code. Most of the generation tools insert a warning into the code "This is computer generated code. All changes will be lost if this code is generated again ..." or something like that, but are people listening?
Possible solution in your case
OK, enough dawn ...
Is there a way to make changes to existing code without overwriting it?
Do it manually (provided that it is not a disturbing change)!
It takes some time, but it’s not difficult. You take the source WSDL and generate the code for it in a separate folder: Folder1. Take the new WSDL and create code for it in another separate folder: Folder2. Make a difference between the two directories to see which files have been modified. Browse the files.
Now you know how your code should be modified in existing project code. Now you need to find out if the changed code was generated somehow after it was created. Compare the project folder with Folder1.
Then make the changes manually.
If this is a mutable change instead, you might want to check if clients can be migrated. If not, you may need to expose your web service at two endpoints, each with its own WSDL contract, on the same web service and reconfigure clients over time, if possible.