Re: Big-Picture Question (Web Services, RegNow)
- From: Laurent Bugnion <galasoft-lb@xxxxxxxxxx>
- Date: Sat, 18 Nov 2006 22:46:24 +0100
Hi,
Jonathan Wood wrote:
Laurent,
The constraints for web methods are exactly the same as for "normal" methods: One return value only, but it can be anything including array (if you have many "fields" of the same type), or an object including different properties.
That's interesting. I tried using out parameters but the VS 2005 testing mechanism for asmx files does not support that. I just tried returning a string array. This is supported. Unfortunately, there is no way to name each of the string fields returned.
An array's fields are not named. Once again, it's the same as for a normal method.
However, if you can, I recommend to keep it simple. First you'll avoid serialization problems, and second, remember that web services clients are not only C#, but could be anything, including JavaScript (it's quite easy to make a web service call using JavaScript). For example, instead of transmitting a DateTime object, why not transmit a string representation of that DateTime... you get the idea.
Yes, and I agree wholeheartedly. However, I'm writing a service that provides a registration code for my software. It seems like it would be more straightforward (and more standard?) to include two return values: One that indicate success or failure, and another that provides the registration code (or error message on failure).
That's easy to do. Create a class:
public class ReturnValue
{
public bool success = false;
public string registrationCode = "";
}
then, in your web method, declare:
[WebMethod]
public ReturnValue GetRegistrationCode()
{
ReturnValue returnValue = new ReturnValue();
returnValue.success = true;
returnValue.registrationCode = "1234";
return returnValue;
}
As easy as that.
I don't want to do anything that is out of the ordinary but it seems like this would be a good, simple approach, one for which XML is well suited. If this is not at all standard, I could include a pass/fail string at the start of my return string. But only seems like it would be harder for the consumer of my Web service to deal with.
Thanks!
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
.
- Follow-Ups:
- Re: Big-Picture Question (Web Services, RegNow)
- From: Jonathan Wood
- Re: Big-Picture Question (Web Services, RegNow)
- References:
- Big-Picture Question (Web Services, RegNow)
- From: Jonathan Wood
- Re: Big-Picture Question (Web Services, RegNow)
- From: Mark Rae
- Re: Big-Picture Question (Web Services, RegNow)
- From: Jonathan Wood
- Re: Big-Picture Question (Web Services, RegNow)
- From: Laurent Bugnion
- Re: Big-Picture Question (Web Services, RegNow)
- From: Jonathan Wood
- Big-Picture Question (Web Services, RegNow)
- Prev by Date: Re: Big-Picture Question (Web Services, RegNow)
- Next by Date: Interesting Project
- Previous by thread: Re: Big-Picture Question (Web Services, RegNow)
- Next by thread: Re: Big-Picture Question (Web Services, RegNow)
- Index(es):
Relevant Pages
|