webservice
-
This should be pretty easy but I'm having so many problems with it. I'm following someone elses code and cant figure out how he did this. One of the webmethods returns 3 parameters and it uses a class of somesort to do it. We had to reverse engineer to get the code so its not complete. [WebMethod] Public Class1 HelloWorld(int i1, string str1, string str2) { try } //Code } Catch } return Class1(1,2,3) } { return Class1(0,0,0) } } How is this possible? Thanks in advance.
-
This should be pretty easy but I'm having so many problems with it. I'm following someone elses code and cant figure out how he did this. One of the webmethods returns 3 parameters and it uses a class of somesort to do it. We had to reverse engineer to get the code so its not complete. [WebMethod] Public Class1 HelloWorld(int i1, string str1, string str2) { try } //Code } Catch } return Class1(1,2,3) } { return Class1(0,0,0) } } How is this possible? Thanks in advance.
If you declare the class with the Serializable value then ASP.NET will take care of translating it into an XML datatype when it is returned. The added benefit of returning the class, besides returning multiple values, is that the XML elements will have the same name as the fields which in this example are Field1, Field2, and Field3.
[Serializable] public class Class1 { private string _field1; private string _field2; private string _field3; public Class1() { } public Class1(string Value1, string Value2, string Value3) { this._field1 = Value1; this._field2 = Value2; this._field3 = Value3; } public string Field1 { get { return this._field1; } set { this._field1 = value; } } public string Field2 { get { return this._field2; } set { this._field2 = value; } } public string Field3 { get { return this._field3; } set { this._field3 = value; } } }