int/out params with c#

Silas2
Silas2 used Ask the Experts™
on
I'm using an async pattern with c# and wcf. I've got a param I just want to pass straight thru. I've ended up by haveing the param as an in and an out, i.e. twice. Is that the most elegant way of doing it with WCF async?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2008

Commented:
The preferred method is to use a ref or out parameter:

Synchronous and Asynchronous Operations
http://msdn.microsoft.com/en-us/library/ms734701.aspx

[OperationContract(AsyncPattern=true)]
IAsyncResult BeginDoWork(string data, 
                          ref string inout, 
                          AsyncCallback callback, 
                          object state);
int EndDoWork(ref string inout, out string outonly, IAsyncResult result);

Open in new window

Author

Commented:
But you can't use a ref with wcf. I think maybe the data contract approach might be (whilst a bit overkill) preferrable.
Most Valuable Expert 2012
Top Expert 2008
Commented:
That's an ugly rumor that needs to be investigated:

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

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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial