views:

290

answers:

2

I have a simple class, let's say "Team" and I expose a WCF service (basicHttpBinding, hosted in IIS) with a GetTeams operation which returns an array of Team.

The Team class looks like

[DataContract]
public class Team
{
    [DataMember]
    public int Id { get; set; }
    [DataMember]
    public Point Position { get; set; }
    [DataMember]
    public string Code { get; set; }
    [DataMember]
    public bool Available { get; set; }
    [DataMember]
    public string Extra { get; set; }
    [DataMember]
    public double X { get; set; }
    [DataMember]
    public double Y { get; set; }
}

On the client (Silverlight 3.0 app) I get all the data but the Position property holds a default Point instance. The Point struct is System.Windows.Media.Point which is serializable. I also added the X and Y properties to duplicate the Position data to see if it gets right on the other end of the wire.

The XML intercepted (thanks, Firebug!) looks like so:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
<s:Body>
 <GetTeamsResponse xmlns="http://tempuri.org/"&gt;
  <GetTeamsResult xmlns:a="http://schemas.datacontract.org/2004/07/MyProject.Data" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
   <a:Team>
    <a:Code>A23HJGF23</a:Code>
    <a:Available>true</a:Available>
    <a:Extra i:nil="true"/>
    <a:Id>1</a:Id>
    <a:Position xmlns:b="http://schemas.datacontract.org/2004/07/System.Windows"&gt;
     <b:_x>572194.59937858</b:_x>
     <b:_y>322518.3889979</b:_y>
    </a:Position>
    <a:X>572194.59937858</a:X>
    <a:Y>322518.3889979</a:Y>
   </a:Team>
   <!-- other <a:Team> elements -->
  </GetTeamsResult>
 </GetTeamsResponse>
</s:Body>
</s:Envelope>

Therefore it seems there is a deserialization issue. No exception is thrown!

Why?

+1  A: 

Just as a quick clarification, is your WCF service returning the .net 3 / 3.5 point class whilst the SL is attempting to use the SL point class? Or are they both referring to the same point structure.

I'm thinking you are passing the .Net version to the SL version because that namespace in the position datacontract seems to indicate your using the CLR / WPF point, which is not the same as the SL point.

The WCF endpoint will use the ISerializable to change to the XMLSerializer instead of the data contract serializer, so you will see the data, but as a custom class with the _x and _y you see in the XML at present.

Edit:

For clarity over the struct location

SL3 Point Struct is in System.Windows.DLL (http://msdn.microsoft.com/en-us/library/system.windows.point%28VS.95%29.aspx) .Net 3.0 Point Struct is in windowsbase.dll (http://msdn.microsoft.com/en-us/library/system.windows.point%28VS.85%29.aspx) .Net 3.5 Point Struct in WindowsBase.dll (http://msdn.microsoft.com/en-us/library/system.windows.point.aspx)

Same name, not the same class however when comparing the .net to the SL.

And a bit of an addition, it occuring in SL 2.0 and being reported on the SL website. (http://silverlight.net/forums/t/26577.aspx)

Andrew
The System.Windows.Point structure is part of .NET 3.0 and upwards in the WindowsBase assembly. Silverlight refers to the same structure.
Andrei Rinea
SL Point is in C:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v3.0\System.Windows.dll.Net3.5 Point is in C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dllIn my object browser I have two distinct Point structs, 1 for SL, 1 for .Net 3.0 - worth checking.
Andrew
that should of been the .net3.0 point obviously given the framework 3.0 folder name.
Andrew
+1  A: 

Looks like the client does not recognise the data type Point.

As you point out System.Windows.Media.Point is in .Net 3.0 and Silverlight.

You could try declaring Point as System.Windows.Media.Point in your data contract. Also make sure that the necessary dll's is referenced in the client project.

Shiraz Bhaiji