0 votes
in C Sharp by

Q. What is a service contract in WCF?

1 Answer

0 votes
by

A 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";
    }
}
...