Object being passed using webmethod, loses some values, but not all
I'll try to explain everything clearly.
when calling a webmethod
[WebMethod]
public Profile synchronize(string MID, DeviceUploadData data)
The object DeviceUploadData has many properties, and a few of them are array's. My question is about the array specifically. It loses it's value once it's received on the webmethod end.
This is the property inside DeviceUploadData
Private 开发者_如何学Pythondata() As DataObject
Public Property Data() As DataObject()
Get
Return Me.data
End Get
Set(value As DataObject())
Me.data = value
End Set
End Property
This is the DataObject object inside
<System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.225"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://somethingsomething")> _
Public Class DataObject
Dim _calories As Double
Public Property Calories() As Double
Get
Return _calories
End Get
Set(value As Double)
_calories = value
End Set
End Property
End Class
This is the DeviceUploadData object on the webmethod end
public class DataObject
{
private List<DataObject> _data;
public List<DataObject> data
{
get { return _data; }
set { _data = value; }
}
}
This is the DataObject on the webmethod end
public class DataObject
{
#region class variables
double _calories;
public double Calories
{
get { return _calories; }
set { _calories = value; }
}
}
So the DataObject is populated with data, then once passed, on the other end, some of the DataObject properties are no longer populated. I haven't included the other properties in this example.
Solved it! All parameters and methods have to named exactly the same in the client and web object.
I guess it would be hard to see in my example since I've labled them the same.
Hope this helps some people out there.
精彩评论