支持API的最佳实践是什么?
从2004年起,我有this article声称没有实际的标准,只有最佳做法。任何更好的解决方案?您如何解决WS版本控制?
问题描述
系统A
客户
class SystemAClIEnt{ SystemBServiceStub systemB; public voID consumeFromB(){ SystemBObject bObject = systemB.getSomethingFromB(new SomethingFromBRequest("someKey")); }}
服务
class SystemAService{ public SystemAObject getSomethingFromA(SomethingFromARequest req){ return new SystemAObjectFactory.getobject(req); }}
可转移对象
版本1
class SystemAObject{ Integer ID; String name; ... // getters and setters etc;}
版本2
class SystemAObject{ Long ID; String name; String description; ... // getters and setters etc;}
请求对象
版本1
class SomethingFromARequest { Integer requestedID; ... // getters and setters etc;}
版本2
class SomethingFromARequest { Long requestedID; ... // getters and setters etc;}
系统B
客户
class SystemBClIEnt{ SystemAServiceStub systemA; public voID consumeFromA(){ SystemAObject aObject = systemA.getSomethingFromA(new SomethingFromARequest(1)); aObject.getDescription() // fail point // do something with it... }}
服务
class SystemBService{ public SystemBObject getSomethingFromB(SomethingFromBRequest req){ return new SystemBObjectFactory.getobject(req); }}
可转移对象
版本1
class SystemBObject{ String key; Integer year; Integer month; Integer day; ... // getters and setters etc;}
版本2
class SystemBObject{ String key; BDate date; ... // getters and setters etc;}class BDate{ Integer year; Integer month; Integer day; ... // getters and setters etc;}
请求对象
版本1
class SomethingFromBRequest { String key; ... // getters and setters etc;}
版本2
class SomethingFromBRequest { String key; BDate afterDate; BDate beforeDate; ... // getters and setters etc;}
失败方案
如果系统A版本1的客户端调用版本2的系统B服务,它可能会失败:
> SystemBObject(getYear(),getMonth(),getDay())的缺少方法
>未知类型BDate
如果系统A版本2的客户端调用版本1的系统B服务,它可能会失败:
>未知类型在SomethingFromBRequest上的BDate(客户端使用B版本1无法识别的较新的B请求对象)
>如果System A客户端足够聪明地使用请求对象的版本1,则可能会在SystemBObject对象(getDate())上的缺少方法上失败
如果版本1的系统B客户端调用版本2的系统A服务,它可能会失败:
>在SystemAObject上键入missmatch或溢出(返回长但预期的整数)
如果版本2的系统B客户端调用版本1的系统A服务,则可能会失败:
>在SystemARequest上键入missmatch或溢出(请求Long而不是整数)
>如果请求通过某种方式转换问题(stub是Long,但服务返回一个整数在所有的WS实现中都不会非常兼容)
可能的解决方案
>推进版本时使用数字:例如SystemAObject1,SystemBRequest2等,但是缺少一个用于匹配源/目标版本的API
>在签名中,传递XML而不是对象(yuck,以XML格式传递转义的XML,双重序列化,反序列化/解析,解析)
>其他:例如文件/文字/ WS-I有补救吗?
http://API.salesforce.com/{version}/{servicename}
所以你会有一个Web服务URL:
http://API.salesforce.com/14/Leadhttp://API.salesforce.com/15/Lead
等等…
通过这种方法,您将获得以下好处:
>你总是知道你在说什么版本。>保持向后兼容性。>你不必担心依赖问题。每个版本都有完整的服务。您只需确保不要在呼叫之间混合版本(但这取决于服务的消费者,而不是您作为开发人员)。
总结以上是内存溢出为你收集整理的Web服务 – 您的WebService版本控制最佳实践是什么?全部内容,希望文章能够帮你解决Web服务 – 您的WebService版本控制最佳实践是什么?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)