WSDL enumeration restriction with key / value pairs

I am working on a SOAP web service that has many input fields using enumeration restrictions.

These listings are very similar to the HTML select / select setting; I expect a specific value to be returned, but the label of that value should be open using WSDL.

Example: a client wants to add an insurance policy for his home and, therefore, must indicate the type of building involved.

<xsd:restriction base="xsd:string"> <xsd:enumeration value="00001" /> <xsd:enumeration value="00002" /> <xsd:enumeration value="00003" /> </xsd:restriction> 

However, the client still does not understand what the values ​​1, 2 and 3 are. So, something like this:

 <xsd:restriction base="xsd:string"> <xsd:enumeration value="00001" label="Brick and mortar" /> <xsd:enumeration value="00002" label="Straw" /> <xsd:enumeration value="00003" label="Aircastle" /> </xsd:restriction> 

it would be great if the client were used to display these labels for the user.

Is there a standard WSDL annotation / syntax for this construct?

+6
source share
1 answer

Is there a standard WSDL annotation / syntax for this construct?

I'm afraid not. The enumeration XML schema is used to limit the value within a specific set of possible values. When your client sends you a request, an element with a restriction type will be allowed to have (in your case) the value 00001, 00002 or 00003, or it will be invalid.

The restriction defines only values; you cannot add labels. You could at best add <annotation> , but that would be just documentation. In the client’s user interface, each client must say that 00001 is actually “brick and mortar”, and 00002 is “straw”, etc.

If you don't want to do this and instead want to return labels as well, you need a slightly more complex object, perhaps something like this:

 <option> <key>00001</key> <label>Brick and mortar</label> </option> 

You provide a shortcut and restrict the key to a scheme like:

 <xsd:simpleType name="ValuesType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="00001" /> <xsd:enumeration value="00002" /> <xsd:enumeration value="00003" /> </xsd:restriction> </xsd:simpleType> <xsd:complexType name="OptionType"> <xsd:sequence> <xsd:element name="key" type="ValuesType" /> <xsd:element name="label" type="xsd:string" /> </xsd:sequence> </xsd:complexType> 

You can return the list of parameters to clients, and they can present it in the interface with key as a value and label as the text of parameters in the <select> inputs, while upon request you will return the selected value (i.e. the selected key ).

+6
source

Source: https://habr.com/ru/post/910904/


All Articles