Sachin Gaur
Sachin Gaur

Reputation: 13099

using reference parameter for a web method in .NET

I am working on a web application that consumes a web service. Web service is written in .NET.

I want to know whether using a reference parameter for a Web method is a good practice or not?

Upvotes: 0

Views: 387

Answers (2)

Keith
Keith

Reputation: 155602

You can use ref and out params with WCF services, but under the hood they're wrapped up.

Anything passed to a WebMethod or service has to be serialised - you can make it behave as if it is a ref or out by wrapping it in something that sets the values back, but this is messy.

You're better off with a record class - a simple serialisable class that's basically just a list of auto properties that's the return of the WebMethod.

This results in extra classes, but is much easier to maintain.

Upvotes: 2

eglasius
eglasius

Reputation: 36027

It is best to have the ws message based.

You can still be doing so implicitly when you use multiple parameters, there is still the message you are receiving with those. Just keep them separated, if you need multiple outputs return a simple result class for the operation.

Upvotes: 0

Related Questions