WCF服务中的单向操作

时间:2014-01-31 08:50:02

标签: wcf

我是wcf的新手。所以经常阅读基础教程&来自wcf的许多网站的指南。我看到人们使用[OperationContract(IsOneWay=true)]

等特殊属性设计他们的wcf服务
[ServiceContract]
public interface IArticleService
{
   [OperationContract(IsOneWay=true)]
   void OneWayMethod();
}
在阅读了这个单向操作后,我明白它是什么如下.... 当操作没有返回值时,客户端不关心调用的成功或失败。 WCF提供单向操作来支持这种即发即弃调用:一旦客户端发出调用,WCF就会生成一条请求消息,但是没有相关的回复消息会返回给客户端

我想知道如果我没有指定IsOneWay = true或IsOneWay = false,那么IsOneWay = true是默认值。告诉我当我们没有指定这个属性时会发生什么?IsOneWay = true?

或指定类似IsOneWay = false

感谢

更新

我从这个网址 http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.isoneway%28v=vs.110%29.aspx 读了一篇文章,了解IsOneWay = true或IsOneWay = false

的含义是什么
[ServiceContract]
public class OneAndTwoWay
{
  // The client waits until a response message appears.
  [OperationContract]
  public int MethodOne (int x, out int y)
  {
    y = 34;
    return 0;
  }

  // The client waits until an empty response message appears.
  [OperationContract]
  public void MethodTwo (int x)
  {
    return;
  }

  // The client returns as soon as an outbound message
  // is queued for dispatch to the service; no response
  // message is generated or sent.
  [OperationContract(IsOneWay=true)]
  public void MethodThree (int x)
  {
    return;
  }
}

1 个答案:

答案 0 :(得分:0)

默认情况下IsOneway为false,如果您希望操作是单向的,则必须将其显式设置为true

检查出来:

http://msdn.microsoft.com/en-us/library/ms733035(v=vs.110).aspx