Learn how to a build a cloud-first strategyRegister Now


What is the NameSpace attribute in a WCF DataContract and why should I use it?

Posted on 2012-09-02
Medium Priority
Last Modified: 2012-09-03

I'm a Newbie to the world of WCF.

I've got some very basic questions regarding namespaces.

When you specifiy a DataContract on a class, you have the ability to specify the NameSpace attribute.

I've got some basic WCF services defined within VS2010 and am successfully calling the services within a client in the same solution. I'm not explicitly defining the NameSpace attribute.

In straightforward terms, what is the NameSpace attribute?
Why do I need to use it?

I'm fiddling around with trying to implement some generic ErrorHandling using the IErrorHandler interface. One of the parameters for creating a new SenderFaultCode is to provide a namespace. I'm not clear on what I should be using here.
Question by:jxbma
  • 2
LVL 18

Accepted Solution

DarrenD earned 2000 total points
ID: 38360603

Have a look at this article.


Hope this helps,

LVL 18

Assisted Solution

DarrenD earned 2000 total points
ID: 38360605
LVL 14

Expert Comment

by:Vel Eous
ID: 38360643
A namespace can be thought of as an abstract container for logical unique identifiers (your objects).  An object created within a namespace is associated with that namespace and that namespace alone.

One reason that this is of interest is due to the requirement that identifiers must be unique.  Namespaces allow the use of the same identifier name assuming they are not in the same namespace.  So for example if you were developing an application which had the identifier "MyClass" in the namespace "MyDefaultNamespace", you would get the error 'MyDefaultNamespace' already contains a definition for 'MyClass' if you were to attempt to define "MyClass" again.  However if in the same application you defined another namespace "MySecondNamespace", you could happily define another "MyClass" within this namespace and receive no error.

Obviously that is a very basic example, however, it gives you an idea of that principle.  It is most beneficial when you are interacting with other developer APIs/systems which may themselves have an identifier that you want to use in your application.  Thanks to namespaces this is possible.

Another benefit of namespaces is the grouping aspect, if you take a look at the .NET namespace schema you will notice that associated controls are grouped together in the same namespace for which the namespace provides its description.  For example System.Windows.Controls contains user interaction controls.

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question