Search code examples
wcfxml-namespacesservicecontract

WCF namespace usage


Ok - straight forward and simple question (2 part) - looking for a simple answer.

In a WCF Service contract you can provide a namespace on your contract...

Question is this: First - Why (for real...need solid details here) is the http:// model chosen for the contract namespace naming convention

Second - Once set, how do I leverage...like so? this is in my host -

    <endpoint ... contract="http://helloworld.com/example"></endpoint>

Solution

  • The namespace absolutely does not have to be an http:// URL, it only needs to be any valid URN. It's just about being a uniquely identifiable name. Check out this great article on the differences between URI, URN, URL if you're not familiar.

    As for using it on the WCF client endpoint, you don't. That namespace just scopes the name of the interface in the WSDL. The address at which the service is ultimately hosted can (should) be completely different from the namespaces used when defining the contracts. In fact there could be several endpoints for the exact same contract.

    In WCF client endpoint configuration you use the contract attribute which points to a .NET interface which can either be the same interface as your service, this assumes you're sharing your contract library between client and service, or a "replica" interface that is marked up with a ServiceContract that has the matching values from your service definition (this is what Add Service Reference/svcutil do).