请求-答复服务Request-Reply Services

请求-答复服务是 Windows Communication Foundation (WCF)中的默认操作协定类型。Request-reply services are the default type of operation contract in Windows Communication Foundation (WCF). 客户端调用服务操作并等待服务的响应。Clients make calls to service operations and wait for a response from the service. 你可以同步执行对服务操作的调用(客户端接收到服务的响应或调用超时前客户端将保持阻止状态),也可以异步执行对服务操作的调用(客户端调用服务操作,继续工作,并在其他线程上接收服务的响应)。You can perform calls to a service operation either synchronously, where the client blocks until it receives a response from the service or the call times, or asynchronously, where the client makes a call to the service operation, continues working, and receives the response from the service on another thread.

若要创建请求-答复服务协定,请定义服务协定,然后对每个操作应用 OperationContractAttribute 类,如下面的示例代码所示。To create a request-reply service contract, define your service contract, and apply the OperationContractAttribute class to each operation, as shown in the following sample code.

[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")]  
public interface IRequestReplyCalculator  
{  
    [OperationContract]  
    double Add(double n1, double n2);  
}  

您不必将 IsOneWay 属性设置为 false,因为这是默认行为。You do not have to set the IsOneWay property to false because this is the default behavior.

请参阅See also