Jonathan,
Jonathan said:
Well, I understood you tried it. Did you try running it within the
environment?
Thanks.
I am sorry, I don't understand what you mean with "the environment". Do
you mean that you cannot debug?
This works:
SERVICE:
[WebService(Namespace = "
http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service ()
{
}
public class ContainerClass
{
private string m_strValue = "";
private int m_iValue = 0;
public string strValue
{
get { return m_strValue; }
set
{
if (value == null)
{
value = "";
}
m_strValue = value;
}
}
public int iValue
{
get { return m_iValue; }
set
{
if (value < 0)
{
value = 0;
}
m_iValue = value;
}
}
public ContainerClass()
{
// Only there for serialization
}
public ContainerClass(string strValue, int iValue)
{
this.strValue = strValue;
this.iValue = iValue;
}
}
[WebMethod]
public ContainerClass Execute(ContainerClass param)
{
ContainerClass oReturn
= new ContainerClass(param.strValue, param.iValue);
return oReturn;
}
}
ASPX:
<html xmlns="
http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox runat="server" ID="tfStringValue" Text="" /> (string)
<br />
<asp:TextBox runat="server" ID="tfIntValue" Text="0" /> (int)
<br />
<asp:Button runat="server" ID="bnExecute" Text="Execute" />
<hr />
<asp:Label runat="server" ID="lblResult" Text="" />
</form>
</body>
</html>
ASPX.CS:
public partial class _Default : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.bnExecute.Click += new EventHandler(bnExecute_Click);
}
private void bnExecute_Click(object sender, EventArgs e)
{
try
{
string strValue = tfStringValue.Text;
int iValue = Int32.Parse(tfIntValue.Text);
Service.ContainerClass oParam = new Service.ContainerClass();
oParam.strValue = strValue;
oParam.iValue = iValue;
Service.Service oService = new Service.Service();
Service.ContainerClass oReturn = oService.Execute(oParam);
lblResult.Text = oReturn.strValue + "|" + oReturn.iValue;
lblResult.ForeColor = System.Drawing.Color.Black;
}
catch (Exception ex)
{
lblResult.ForeColor = System.Drawing.Color.Red;
lblResult.Text = ex.Message;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
Note the following: The check introduced in the properties of the class
ContainerClass are not passed to the proxy. It is possible to pass
negative values in the proxy, because the WSDL file only describes the
interface, not the content of the properties or the methods. That can be
confusing.
Other than that, this proves that you can use objects as parameters and
as return values.
HTH,
Laurent