Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In WCF is there a way to set ServiceContract Namespace assembly-wide?

In WCF land, you can specify a Namespace prefix for anything that has a [DataContract] like so:

[DataContract(Namespace="MyApp")] public class whatever...

However if you wanted to apply a common namespace to ALL data contracts assembly-wide, you can use the ContractNamespaceAttribute:

/* in AssemblyInfo.cs */
[assembly: ContractNamespace("MyApp", ClrNamespace = "MyApp")]

/* in whatever.cs */
[DataContract] public class whatever...

Thats great, works fine. Now over on the ServiceContract side, I can do the same Namespace setup on the service interface:

[ServiceContract(Namespace="MyApp")] public interface whateverService...

But is there something comparable to [assembly: ContractNamespace] that can be used to set the Namespace for all [ServiceContract]s? I'd really like to avoid having to set it manually for however many services, its nice having it in 1 place for the data contracts. Since there is an assembly level namespace attribute for the data contracts, i'd hope there is one for the service contracts too...

like image 873
CodingWithSpike Avatar asked Aug 18 '09 19:08

CodingWithSpike


Video Answer


1 Answers

No, you cannot - you have to be very explicit in WCF and you have to explicitly set things like namespaces on each and every ServiceContract. I would probably even do it on each and every DataContract as well - just to be clear about what I am doing.

It's a good thing, though! Being explicit also makes your intentions clear - trust me, in a complex system, that helps !

Marc

like image 188
marc_s Avatar answered Sep 29 '22 18:09

marc_s