1

Hi,

The default namespace of data/servce contracts in WCF is "http://tempuri.org/". By setting the ServiceContract.Namespace and ServiceBehavior.Namespace we can get a custom namespace. I do however got some questions on this :

  1. Do I have to use a http:// namespace or could I name it to the same CLS namespace?
  2. If I need to set all my datacontracts under MyApp.IO to use the CLS namespace is there a simple way to do this without setting all of them manually?
  3. Is there a simple way to set the CLS namespace as contract namespace for the entire service and its datacontracts?
Banshee
  • 15,376
  • 38
  • 128
  • 219

1 Answers1

3

Question 1. The namespace can be anything. People typically use a URI of some form but it does not have to point to an actual web page. Often people will use a version identifier in the namespace but there are no rules about what you should do.

Question 2. See above.

Question 3. You can set the namespace for all contracts like this:

// This overrides the standard namespace mapping for all contracts 
// in Contoso.CRM. 
[assembly: ContractNamespace("http://schemas.example.com/crm",
   ClrNamespace = "Contoso.CRM")]
namespace Contoso.CRM
{
    // The namespace is overridden to become: 
    // http://schemas.example.com/crm.
    // But the name is the default "Customer".
    [DataContract]
    public class Customer
    {
        // Code not shown.
    }
}

You can check out this MSDN Article for more information

Trey Combs
  • 710
  • 5
  • 10
  • Thanks! I tried to set the namespace to the same ClrNamespace and this works? You said that it had to be a URI? why? – Banshee Jul 11 '12 at 06:27
  • 1
    It looks like I read too much into Microsoft's documentation. It can be anything; I will update my answer accordingly. Good catch! – Trey Combs Jul 11 '12 at 13:14