Return value from webmethod problem

J

Justin Dutoit

Hey. I have a function with a boolean return value, called IsInWarehouse,
which checks if a product is available in a warehouse, or not. But I need
security in the function too, so I have
[WebMethod][SoapHeader("soapHeader")]
public bool IsInWarehouse(string productName) {
if (Login(username, password)) {

// query db about available product

} else {
// ???
}
}

If the product is in stock, it returns true, or else it returns false.
But the caller of the web service needs to know if the login succeeded or
failed. (Because it's custom authentication in a web service, authentication
has to be done inside every procedure that needs it) What do I do with the
type of the return value? bool gives you 2 return values, I need 3.

Thanks for any help
Justin Dutoit
 
P

Paul E Collins

Justin Dutoit said:
[returning a boolean but wanting a tri-state]

In general, you can either create an enum for each possible state, and
return one of its members:

public enum QueryResult
{
InWarehouse, NotInWarehouse, QueryFailed
}

.... or use an 'out' parameter, to return more than one value:

public bool IsInWarehouse(string productName, out bool queryFailed)
{
queryFailed = false; // but set to 'true' on failure
...
return productFound; // separate true or false
}

P.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top