WCF Essentials—Names and namespaces
| CSharp-Online.NET:Articles |
| .NET Articles |
| © 2007 O'Reilly Media |
Names and namespaces
You can and should define a namespace for your contract. The contract namespace
serves the same purpose in WCF as it does in .NET programming: to scope a type of
contract and reduce the overall chance for a collision. You use the Namespace property
of the ServiceContract attribute to provide a namespace:
[ServiceContract(Namespace = "MyNamespace")] interface IMyContract {...}
Unspecified, the contract namespace defaults to http://tempuri.org. For outwardfacing
services you would typically use your company’s URL, and for intranet services
you can use any meaningful unique name, such as MyApplication.
By default, the exposed name of the contract will be the name of the interface used.
However, you could use an alias for a contract to expose a different name to the clients
in the metadata using the Name property of the ServiceContract attribute:
[ServiceContract(Name = "IMyContract")] interface IMyOtherContract {...}
In similar manner, the name of the publicly exposed operation defaults to the
method name, but you can use the Name property of the OperationContract attribute
to alias it to a different publicly exposed name:
[ServiceContract] interface IMyContract { [OperationContract(Name = "SomeOperation")] void MyMethod(string text); }
You will see a use for these properties in the next chapter.
|

