Return value from webmethod problem

  • Thread starter Thread starter Justin Dutoit
  • Start date Start date
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
 
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.
 
Back
Top