Welcome to MSDN Blogs Sign in | Join | Help

ContractNamespaceAttribute

Back when I did an overview of custom namespaces, I omitted any namespace declarations that wouldn't appear in the final metadata. One of those declarations is the default namespace for data contracts. I had two example data contracts, one for faults and one for normal messages, although they actually work exactly the same in practice.

[DataContract(Namespace = "http://example.com/faultcontract/datacontract")]
public class MyFault
{
[DataMember]
public string detail;
}

[DataContract(Namespace = "http://example.com/datacontract")]
public class MyData
{
[DataMember]
public string data;
}

These data contracts include an explicitly declared XML namespace. However, you can modify the test program in the earlier article to see what happens when those namespace declarations are removed. What you end up with is an ugly looking namespace based on a fixed prefix http://schemas.datacontract.org/2004/07/ and a suffix that is the CLR namespace.

If you want to get rid of that default namespace for every data contract you define, then you can add a ContractNamespaceAttribute to the assembly. This attribute defines the default XML namespace for data contracts that are located in a particular CLR namespace. You can retrieve a ContractNamespaceAttribute in the standard way for assembly attributes by calling GetCustomAttributes on the assembly with the ContractNamespaceAttribute type.

Next time: Configuring SSL Certificates for Windows Vista

Published Wednesday, October 10, 2007 5:00 AM by Nicholas Allen

Comments

Wednesday, October 10, 2007 2:05 PM by Nicholas Allen's Indigo Blog

# Unblocking Flow Throttles

Last time, we were looking at how to control flow through a channel pump by introducing the concept of

New Comments to this post are disabled
 
Page view tracker