Re: Big-Picture Question (Web Services, RegNow)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • RE: Ajax AutoCompleteExtender is Auto-Calculating
    ... You must add apostrophe symbol before and after string inserted in web ... service array. ... AutoCompleteExtender is not the data that resides in the database, ... data being returned by the web service the AutoCompleteExtender consumes. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Soap Request containing an array?
    ... that requires input as an array of a particular data structure and I ... public a1 as string ... dim myRequestStructure as new com.xxx.xxx.xxx.etc.RequestStructure ... But, that creates a problem when I get to the actual web service call, ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Web Service method works on local machine but fails on remote
    ... You might be right becasue I chnaged my code to accept a byte array and then ... foreach (byte t in byteArray) ... exception which say unavble to convert a string to byte. ... I have a web service method which works fine when called from my local ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Error: Index is outside the bounds of the array
    ... to which is outside the bounds of the array. ... SqlConnection sqlconnection1 = new SqlConnection; ... Object returnValue; ... string CustomerId, string Alias, string UserName) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Big-Picture Question (Web Services, RegNow)
    ... but it can be anything including array (if ... of the string fields returned. ... to make a web service call using JavaScript). ... (or error message on failure). ...
    (microsoft.public.dotnet.framework.aspnet)