What is the format of the DataContractAttribute.Namespace Property?
Asked Answered
L

2

1

This MSDN article recommends always to provide a namespace to a ServiceContract and DataContract.

Examples usually have a "schema" prefix and a URI type pattern for the namespace such as

Namespace="urn:WCFEssentials/Samples/2008/12"

instead of a traditional C# namespace with dot-notation such as

Namespace="MyNamespace.MyDataClasses"

What is the suggested format the namespace property? Do we need the schema prefix? Why is this format suggested?

Lodged answered 19/3, 2014 at 20:3 Comment(0)
C
1

It's an XML Namespace. Those can either be in the urn: format or they can be URLs.

Cenesthesia answered 19/3, 2014 at 20:19 Comment(1)
Here is more info from W3 on the "urn" prefix: w3.org/Addressing/URL/URI_URN.htmlLodged
L
3

Here are some additional suggestions from MSDN:

  • The namespace can be any string
  • but is traditionally a Uri representative of the company or application domain
  • and includes a year and month to support versioning scenarios.
  • For DataContracts, the namespace is often similar to the ServiceContract namespace
  • but uses using a “schemas” uri section

Example Service Contract with Namespace

[ServiceContract(Namespace="urn:CompanyName/ApplicationName/YYYY/MM")]
[ServiceContract(Namespace="urn:BigFont/EmailSystem/2014/03")]

Example Data Contract with "Schema" Segment in Namespace

[DataContract(Namespace="urn:CompanyName/Schema/YYYY/MM")]
[DataContract(Namespace="urn:BigFont/Schema/2014/03")]

Thank you to John Saunders or getting me started.

Lodged answered 19/3, 2014 at 20:49 Comment(0)
C
1

It's an XML Namespace. Those can either be in the urn: format or they can be URLs.

Cenesthesia answered 19/3, 2014 at 20:19 Comment(1)
Here is more info from W3 on the "urn" prefix: w3.org/Addressing/URL/URI_URN.htmlLodged

© 2022 - 2024 — McMap. All rights reserved.