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



Hi,

Jonathan Wood wrote:
Laurent,

Cool! That gives me all the control I need. The book I'm reading said it was better to stick with basic types but I didn't realize that a class that contained only public basic types would work as well! That gives me complete flexibility on the results!

For giggles, I also tried accepting a class as the argument (since I have quite a few input args). That would be cool also. Unfortunately, the VS Web service test mechanism did not support this, which makes me think others might not support it either, so I'll avoid that.

Show the code. Accepting custom types as parameters should also be supported.

However, note that there are all kind of clients able to send a request to a web service. The given client is responsible for serializing (i.e. transforming into XML) the given parameters, and for deserialiazing (i.e. transforming from XML) the returned value.

If your client is a .NET application, you don't have to worry too much about it, because the serialization/deserialization mechanism is automatically provided (by the web reference, also called web service proxy).


BTW, can you tell me the effect of initializing class variables as you did? That would seem to bypass the constructor somewhat. I didn't realize you could do that.

What I did, for simplification, was provide public attributes in the class. It is not recommended in normal cases, because anyone could modify the attributes at any time. However, for simple "packing" when using a web service, that might be sufficient.

When an attribute is public, you can set and get its value without using properties. Normally, the usual way is rather to create private attributes, and to provide public get and set accessors, named properties. In that case, you can choose to initialize the variables using the constructor.

The following 2 examples are stictly equivalent as for the result of the operation.

Example 1:

public class Test1
{
public int attrib1 = 0;
}

Test1 test1 = new Test1();
test1.attrib1 = 5;

Example 2:

public class Test2
{
private int attrib2 = 0;
public int Attrib2
{
get { return attrib2; }
set { attrib2 = value; }
}
}

Test2 test2 = new Test2();
test2.Attrib2 = 5;

Example 3:

public class Test3
{
private int attrib3 = 0;
public int Attrib3
{
get { return attrib3; }
set { attrib3 = value; }
}

public Test3( int param3 )
{
attrib3 = param3;
}
}

The differences are:

In the case 2 and 3, you can introduce additional checks in the "set" property. For example, you may throw an exception if the value is smaller than 0.

In the case 3, you make sure that the attributes are always initialized. There is no default constructor. (The examples 1 and 2 also don't have an explicit default constructor, but the compiler provides one when no constructor is defined.)

Note that this has nothing to do with web services, it's basic C#. Don't hesitate to ask more if something is not clear.

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: Preserve whitespace
    ... > I am consuming a web service in my asp.net application. ... > web references in Visual Studio by pointing to a wsdl file. ... > System.AsyncCallback callback, object asyncState) { ... > public class mthAddINProviderResponseOutVar_0MthAddINProvider_outputStatus ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Retriving Inherited Objects in an Array
    ... public class Application ... When the Jade web service returns these paramaters. ... <Student xmlns:xsd="http://www.w3.org/2001/XMLSchema " ...
    (microsoft.public.dotnet.framework.webservices)
  • SOAP header problem, using WCF.
    ... public class Authentication: SoapHeader ... public String user; ... Now i need to write same Web Service, using .NET Framework 3.0, because ...
    (microsoft.public.dotnet.languages.csharp)
  • XmlSerializer and the XmlRootAttribute ?
    ... I'm having trouble controlling the Xml content that is created by the ... XmlSerializer when i make a web service call from a proxy, ... public class ServerLongClassName1 ...
    (microsoft.public.dotnet.framework.aspnet.webservices)