What is a service contract in WCF?

Technology CommunityCategory: WCFWhat is a service contract in WCF?
VietMX Staff asked 3 years ago

service contract defines the operations which are exposed by the service to the outside world. A service contract is the interface of the WCF service and it tells the outside world what the service can do. It may have service-level settings, such as the name of the service and namespace for the service.

[ServiceContract]
interface IMyContract { 
    [OperationContract]
	string MyMethod();
}

class MyService: IMyContract {
	public string MyMethod() {
		return "Hello World";
	}
}