Question

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?
Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top