0

Need a suggestion on Java Web Service(SOAP) Message format. Thinking of two message formats.

Could you please share your thoughts on these approaches. What would you recommend?

1) Specific Message Format Specifying the message nodes with the actual names of the data attributes like User first name , last name, ssn .... etc. see the sample below

Pros: Message xsd will have the actual data types for the data to be propagated. This ensures the data is valid.

Cons: Changes to the message format will lead to the xsd change which in turn lead to multiple versions of the service. this would cost the maintenance of the different versions of the service.

2) Generic Message Format Specifying the message nodes with the name value pairs. See the example message below.

Pros: Additional data can be sent with additional properties wihtout changing the message format. Single version of the message can be maintained easily.

Cons: Data is not typed and can not be validated. Service implementation needs to hard code the property names, parse the data, validate the data. Handling data with multiple values would be with some separator like comma(,). Handling the formatted data for the dates, time, currency data ... etc would be expensive.

Specific Format Message

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <soap:Body>
            <ns1:myTestServiceOperation xmlns:ns1="http://xmlns.myenterprise.com/myenterprise/myTestWebService/types/">
            <UserInfo>
                <BioData>
                    <FirstName>John</FirstName>
                    <LastName>Smith</LastName>
                    <SSN>123-34-567</PersonNumber>
                    <DateOfBirth>09/01/1980</DataOfBirth>
                </BioData>
                <EducationalInfo>
                     <Qualification>Master of Science</Qualification>
                     <Institute>ABC</Institure>     
                     <CourseDuration>2 Years</CourseDuration>            
                </EducationalInfo>
                <EmploymentInfo>
                 <JobTile>Administrator</JobTitle>
                 <Employer>XYZ Corp</Employer>
                <EmploymentInfo>
           </UserInfo>
         </ns1:myTestServiceOperation>
        </soap:Body>
</soap:Envelope>

Generic Format Message

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns1:myTestServiceOperation xmlns:ns1="http://xmlns.myenterprise.com/myenterprise/myTestWebService/types/">
        <Record category="BioData">
                <Property name="FirstName" value="John"/>
                <Property name="LastName" value="Smith"/>
                <Property name="SSN" value="123-34-567"/>
        </Record>   
        <Record category="Education">
                <Property name="Qualification" value="Master of Science"/>
                <Property name="Institute" value="ABC"/>
                <Property name="CourseDuration" value="2 Years"/>
        </Record>  
        <Record category="Employment">
                <Property name="JobTile" value="Manager"/>
                <Property name="XYZ Corp" value="XYZ Corp"/>
                <Property name="CourseDuration" value="2 Years"/>
        </Record>      
     </ns1:myTestServiceOperation>
    </soap:Body>
</soap:Envelope>
Peddi
  • 92
  • 1
  • 9

1 Answers1

1

Having a generic schema for a service is a bad idea, except in a handful of cases, such as response of a database query (Same service used to query different tables and different columns)

If there is probability of schema change very frequently, the consumers are affected way more than the producer. So it would be better to have multiple versions of the service running, however that requires more effort.

However, you can always use request and response transformation to have only one version of service running, here's how.

  1. Detect the version of the incoming request (a version element on the schema should do it along with XPATH)
  2. Use a XML transformer like Contivo to convert the incoming request to latest request version
  3. Send this converted XML to the service to respond. Remember that you are only running the latest version of the service
  4. Now transform the output XML to the old version, same as the request, and send back to client.

e.g.

  1. Client sends request with schema version 1
  2. Convert request to latest version, say 12
  3. Send request version 12 to service
  4. Get response version 12
  5. Convert response version 12 to response version 1
  6. Reply to Client with response version 1
Pradeep Pati
  • 5,779
  • 3
  • 29
  • 43