• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 667
  • Last Modified:

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

Hi:

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.
0
jxbma
Asked:
jxbma
  • 2
2 Solutions
 
DarrenDCommented:
Hi,

Have a look at this article.

http://rebuildall.umbraworks.net/2010/11/10/WCF_service_namespaces

Hope this helps,

Darren
0
 
DarrenDCommented:
0
 
Vel EousResearch & Development ManagerCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now