Are WCF 'ref' arguments good or bad?

I recently saw a WCF service declaring operating contracts with ref arguments.

I don’t know why this design decision was made (operations are not valid), but, in addition, I cannot - from my knowledge of WCF - say whether this is good practice or not. Or if it is not relevant.

What do you think?

+6
web-services arguments wcf
source share
3 answers

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 Exit and Return Options

In most cases, you can use out and ref (ByRef in Visual Basic) in the parameters (ByVal in Visual Basic). Because ref parameters indicate that the data is returned from the operation, for example, the following: a request / response operation is required, even if the signature operation returns void.

+5
source share

WCF is not a "remote object call" method or anything - it's pure messaging. Thus, havnig the "by-ref" parameter can be compiled, but it really won’t do anything useful.

On your client, you have a method with the parameters that you call. Then the WCF intercepts this call, packs the parameters and any additional information needed in the message, serializes this message (in text or binary XML) and sends this message to the server via posting.

The server then deserializes the messages back to the parameter set, and the dispatcher component on the server then creates an instance of the service class and calls the appropriate method for this instance of the service class with the parameters from the message.

The whole story runs back for the response sent by the server.

But then again: all that you exchange between the client and the server is a serialized message - there is absolutely no point in creating a “by ref” parameter - it cannot be a by-ref parameter, in the end. Server and client are completely separate worlds, completely separate objects and classes - they just look the same on the wire.

So, I think that the one who wrote this WCF method did not understand the principles of transmitting a WCF message, but was tricked by how WCF feels - just like a method call. But in the end, it's not just a method call.

+4
source share

I'm with marc_s.

you need to be very careful.

WCF always assigns a new instance of this object; it does not just change its contents.

As mars_s has already explained, wcf is a messaging medium. Its nature is to send and receive messages about it.

I find it good practice to always define inside and outside the message. Your sericve interface will be easier to understand and maintain.

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

+1
source share

All Articles