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...
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With