Skip to content

ByRef Parameters Overview

tylerje edited this page Oct 23, 2014 · 1 revision

ServiceWire supports reference and out parameters. Except for non-primitive value types such as decimal and Guid or custom structs.

MSDN defines primitive types as: Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, and Single.

Examples of supported ByRef parameters

 public interface IByRefExamples
 {
    TestResponse Get(Guid id, string label, double weight, out long quantity);
    long TestLong(out long id1, out long id2);
    List<string> GetItems(Guid id, out TestResponse response, int[] vals);
 }

These will throw an exception

 public interface IByRefBadExamples
 {
    TestResponse Get(Guid id, string label, double weight, out decimal quantity);
    long TestLong(out long id1, out Guid id2);
 }

While we do not often recommend the use of ByRef parameters in a service interface, in part because there is no other service library that supports them, sometimes there are advantages to using an out parameter of an int with a return type of a string or any other simple type that will serialize very fast.

Important Note: Normally, one would avoid using value types by ref because they would then have to be boxed and unboxed which comes at a cost to performance. This is true for intra-process implementations, but for inter-process communication through ServiceWire, all value types, whether by ref or not, are boxed in the dynamic proxy in order to be able to pass the parameter arguments as an object array to the underlying channel's invoke method. In the case of inter-process services, one would expect such calls across the "process wire" to be less chatty than an internal method optimized for performance.

Clone this wiki locally