Java – add fields to webservice

I have a soap service that exposes methods

TradeDetail getTradeDetail()

Tradedetail stores five fields, transaction number, date, etc

I need to add a few fields to tradedetail I want to maintain backward compatibility (temporarily), and it seems that my options are limited to creating a new class with additional fields

TradeDetail2 getTradeDetail2()

Now this will work - I've done it before But have people used other solutions?

For example

>Fundamentally change tradedetail2 to add name value pairs. > Inheriting tradedetail2 from tradedetail reduces code but increases coupling > returns XML or JSON instead

I will be able to exit the original interface soon, so the code will be cleaned up and the additional tradedetail2 will never last!

thank you

Solution

I sympathize - some of my web services are full of mymethod(), mymethod2(), mymethod3(), etc. because I need to add some new fields

Do you consciously keep the method name and create a new endpoint for each API version? For example:

> http://my.domain.com/servicename/v1 > http://my.domain.com/servicename/v1.1 > http://my.domain.com/servicename/v1.5 > http://my.domain.com/servicename/v2

Then, no matter how many future changes you need to make, your method name will remain reasonable

Any application that uses your web services may need to rewrite and / or rebuild the new WSDL to take advantage of the new fields, so why not in the new v1.0 Rewrite / rebuild them on the API

I find it helpful to use your service to communicate with the owner / developer of the application – for example, the version [old] of our web service API will no longer be supported after [date], please make sure you use at least the version [new]. "

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>