Bit confused with specifying a namespace for the service contract. Can understand with respect to a normal class,
My understanding about namespace
In normal OOPs model, say Employee class is part of Microsoft name space as well as Google name space. But since we may add reference to Google as well as Microsoft assembly in our project; hence to differentiate Employee’s we have namespace, since when we say
Employee emp = new Employee()… compiler really doesn’t really know which employee we are referring to?
Similarly, with respect to web service how does it matter? May I request an explicit example to explain the case please? For example
[ServiceContract(Namespace="Company.Matching.Algo")]
It’s used – just like regular .NET namespaces – to keep things apart.
Having a namespace helps when you have multiple services that might end up all having similar methods exposed. With a namespace, they can all have a method called
GetVersionor something, and the WSDL document will be able to keep them apart based on their namespace.Also, namespaces are often used for versioning, so your first WCF service might have a service namespace of
http://yourcompany.com/MyService/2011/08and have five methods. If you later on introduce a v2 of your service, which might have 10 methods, and you put it into a separate namespace ofhttp://yourcompany.com/MyService/2011/12then you can keep those things separate – and an “old” client can still call the “old” service with (/2011/08) and use its method, while new clients can already call the new service with more capabilities.