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

Posted on 2012-09-02
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
    LVL 18

    Accepted Solution


    Have a look at this article.

    Hope this helps,

    LVL 18

    Assisted Solution

    LVL 14

    Expert Comment

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    This tutorial will show you how to add an attribute to an XML ( stream returned from a Windows Communication Foundation ( (WCF) Web Service.  Some knowled…
    In previous Articles, we have discussed how we can upload a file using .asmx web service and isolated storage space. Here, in continuation to the topic, I am going to discuss how we can use WCF for the same purpose. Steps: 1.Create the silverli…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now