简体   繁体   中英

WCF IS One Way attribute

我有一个将isoneway属性设置为true的wcf方法。现在当我从客户端调用此服务时,服务将无效的操作异常返回给某些业务场景出错的客户端bcos。我的理解是它将抛出只有endpointnotfound异常和timeoutexception。有人可以解释为什么会这样吗?

Marking your contract as One-Way means exactly that: messages flow in one way only. Clients won't get an answer or wait for the service to execute at all, so there's no way that your client could possibly get a reply or fault from the service most of the time.

If you want that, then maybe a One-Way service isn't for you and what you really want is a two-way service with an empty reply (ie void)

Does the OneWay method return a value or has ref/out parameter? If yes, then that's the reason you are getting InvalidOperationException. This is expected behavior as per MSDN help for OperationContractAttribute.IsOneWay Property ( http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.isoneway(v=vs.110).aspx ).

Look for remarks section, it has following text:

One-way methods must not return a value or have ref or out parameters; otherwise a System.InvalidOperationException exception is thrown.

PS: I know it's too late to reply to the thread, but for someone like me who stumbles across the post after 3 years or so, it might be useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM