开发者

SOAP: How to extend a type without breaking existing clients?

I have a SOAP Service that is implemented using Apache Axis 2. It has a type Message which has the following definition

<xs:complexType name="Message">
  <xs:sequence>
    <xs:element minOccurs="0" name="id" type="xs:int"/>
    <xs:element minOccurs="0" name="caption" nillable="true" type="xs:string"/>
    <xs:element minOccurs="0" name="text" nillable="true" type="xs:string"/>
    <xs:element minOccurs="0" name="source" nillabl开发者_开发问答e="true" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

I have to replace the source element with a reference to a complex type Source. What is the best way to do this while avoiding to break existing clients?


Martin Fowler provided a great article about schema versioning and extension points. Neverthess, as you don't have extension points today this is not an option for you. An approach heavily used in the industry is having more than one version of your WSDLs and XSDs at a given point in time. So if your Web Service is specified using four components:

  1. XML Schema (xsd) describing your data model
  2. WSDL + binding describing the web service by using the XSD
  3. Service provider implemented in Java (the generated code, e.g. JAX-WS)
  4. Service implementation, 'somehow' decoulped from #3

and you are required to introduce non-backward compatible changes, you can duplicate components #1 and #2 and define another namespace for them, e.g. "http://www.example.org/abc_v2". You have to generate a provider for the new version of your service (#3) and 'somehow' integrate it with component #4 - no question, this is the ugly part.

This approach works, although it is not nice as you duplicate a lot of code that wants to be maintained. If you follow this approach you should define a deadline for all clients still using version 1 of your service, so you can get rid of the duplicated code later.

To conclude, not nice but an option.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜