A namespace uniquely identifies a Web service and is specified by the <targetNamespace>
element in the WSDL that represents the service. A data service is simply a Web service with specialized functionality. As a data service implementation is based on XML, namespace handling is an important aspect to it.
When developing a data service, you get to specify namespaces in several places as followsData services are implemented using XML, which means that element names can conflict. Therefore, we use namespaces to uniquely identify the elements defined within a specific web service. Using namespaces for a data service is optional. However, in certain data services, namespaces become necessary. For example, consider a data service with two separate queries using the same set of output mappings. In such situations, you need to use separate namespaces to identify the elements in each query.
Namespaces can be used at different levels for a data service: Table of Contents maxLevel 3 minLevel 3
Service namespace
The service namespace is used to uniquely identify a web service, which means that this namespace applies to all elements in the data service. In the WSDL which that represents the service, it the namespace is indicated by the "targetNamespace" attribute of the WSDL document element. . The service namespace can be overridden at the query level and at output result row level as explained below.
The service namespace can be set using the the Create/Edit Data Service window of the Data Services Server management console as shown below.
For example,
Data service result row namespace
This namespace is set through the Row namespace valueDataserviceresultrownamespace
When you define a query for your data service, you can set a namespace for the elements in the query result section. It associates (output mapping). That is, the Row Namespace applies to all the result rows or result entries of a specific namespace. Therefore, all the subelements in that result raw are under this namespace by default.that you define as output mappings. The example below shows how the row namespace is set for the query result element: Customers.
After setting the row namespace, the Customers element's data type falls under the given namespace. The XML Schema fragment in data types section taken from the service's WSDL is as follows:
Info |
---|
Note the following:
|
Namespaces for specific elements in the result
You might want only selected The row namespace applies to all elements in the query result row to contain a specific namespace. This can be defined by setting the namespace in the output mappings as follows:. Alternatively, you can specify namespaces for selected elements (output mappings) in the query result as shown below.
This is how the setting is reflected in the WSDL.
Info |
---|
Note the following:
|
Namespaces for complex results
In complex results in data services, the result elements can be arbitrarily nested. These nested elements can have their own namespaces. The example below shows how this is represented in a database file fragment, which has a complex result.
Code Block |
---|
<query id="customersInBostonSQL" useConfig="default"> <sql>select * from Customers where city = 'Boston' and country = 'USA'</sql> <result defaultNamespace="http://abc.com/nsb" element="customers" rowName="customer"> <element column="customerName" name="customer-name" xsdType="string"/> <element namespace="http://abc.com/nsb" name="contact"> <element column="contactLastName" name="contact-last-name" xsdType="string"/> <element column="contactFirstName" name="contact-first-name" xsdType="string"/> </element> <element column="phone" name="phone" xsdType="string"/> <element column="city" name="city" xsdType="string"/> <element column="country" name="country" xsdType="string"/> </result> </query> |
The WSDL created for the above service is as follows:
The resulted XML of the executed service is as follows:
Namespace inheritance in a data service
There's an inheritance order where a top-level namespace is inherited by its children. In summary, the inheritance is as follows:
- Service namespace is applied to all aspects of the data service, i.e. results.
- Result row namespace overrides the service namespace and applies a given namespace for the whole result.
- Complex result, nested elements override the result row namespace and assign the namespace to all its child elements.
- A namespace specifically assigned to an element overrides the parent element's namespace and assigns the given namespace to itself.