Are 'by ref' arguments in WCF bad or good?

送分小仙女□ 提交于 2019-11-30 14:17:07
HainesyP

However, According to this Microsoft Article a WCF Call behaves exactly like a Remote Procedure Call and ByRef arguments can be used to return data:-

http://msdn.microsoft.com/en-us/library/ms733070.aspx

Refer to the section: Out and Ref Parameters

In most cases, you can use in parameters (ByVal in Visual Basic) and out and ref parameters (ByRef in Visual Basic). Because both out and ref parameters indicate that data is returned from an operation, an operation signature such as the following specifies that a request/reply operation is required even though the operation signature returns void.

marc_s

WCF is not a "remote object call" method or anything - it's pure message-passing. So havnig a "by-ref" parameter might compile, but it's really not going to do anything useful.

On your client, you have a method with parameters which you call. The WCF runtime then intercepts that call, packages up the parameters and any further information needed into a message, serializes that message (into textual or binary XML), and send that message across the wire to the server.

The server then deserializes the messages back into a set of parameters, and the dispatcher component on the server will then instantiate the service class and call the appropriate method on that service class instance with the parameters from the message.

The whole story works backwards for the reply the server sends back.

But again: all you're exchanging between client and server is a serialized message - there's absolutely no point in making a parameter "by ref" - it cannot possibly be a by-ref parameter, in the end. The server and the client are totally separate worlds, totally separate objects and classes - they just look the same on the wire.

So I think whoever wrote that WCF method didn't understand the principles of WCF message passing, but was lured by the way WCF feels - like just a method call. But it's really not just a method call in the end.

i'm with marc_s.

you need to be very careful.

WCF will always assign a new instance of that object, it not just change its contents.

As mars_s already explained wcf is a messaging-framework. Its nature is to send and receive indipendant messages.

I think a good practice is to always define an in-/ and an out-message. Your sericve-interface will be easier to understand and maintain.

methods with ref- and out-parameters always tend to be very ugly and harder to understand.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!