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")]
By default, WCF services are tied to the (not very useful) http://tempuri.org namespace. Microsoft recommends to replace that namespace with a more meaningful namespace for each service.
[ServiceContract] attribute is used to define a Service contract. This attribute is placed on an interface or a class , which you want to identify as a Service contract.
Remarks. Use the ServiceContractAttribute attribute on an interface (or class) to define a service contract. Then use the OperationContractAttribute attribute on one or more of the class (or interface) methods to define the contract's service operations.
The service contract specifies what operations the service supports. An operation can be thought of as a Web service method. You create service contracts by defining a C# or Visual Basic interface. An interface has the following characteristics: Each method in the interface corresponds to a specific service operation.
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 GetVersion
or 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/08
and 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 of http://yourcompany.com/MyService/2011/12
then 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.
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