Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service Contract Namespace : Why

Tags:

wcf

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")] 
like image 584
Vinay Dwivedi Avatar asked Sep 09 '11 15:09

Vinay Dwivedi


People also ask

Which is the namespace most commonly used in WCF service?

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.

What is service contract attribute?

[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.

What does the service contract attribute do in this interface class?

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.

What is service contract C#?

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.


1 Answers

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.

like image 176
marc_s Avatar answered Sep 23 '22 12:09

marc_s