Question

This is my problem. If I call my callback like so:

clients[computerID].PrintLabelCallback(label);   

The channel faults and I get an CommunicationFault exception on the client side. The call being one way causes no problems on the server side.

If I call it like this however:

label.EntryLocation = null;
label.EntryUser = null;
label.ResultLine = null;
label.Printer = null;
label.Type = null;
clients[computerID].PrintLabelCallback(label);

Where EntryLocation, EntryUser, etc. are classes I've defined. I do NOT have to null out basic types like String, int. Those travel across the wire without incident. It seems like the same types are used on both sides, so I'm not sure where this is failing.

What could cause this? How would I fix it?

edit: Here is the definition of my class and the relevant fields.

[DataContract(IsReference = true), JsonObject(IsReference = false), Serializable]
public partial class Label : Interfaces.IRQSObject
{

    /// <summary>
    /// The location where the Label was created. 
    /// </summary>
    [DataMember(EmitDefaultValue = false)]
    public virtual Location EntryLocation { get; set; }

    /// <summary>
    /// The user that Generated the Label
    /// </summary>
    [DataMember(EmitDefaultValue = false)]
    public virtual User EntryUser { get; set; }

    /// <summary>
    /// The printer that this label will be printed out at 
    /// </summary>
    [DataMember(EmitDefaultValue = false)]
    public virtual LabelPrinter Printer { get; set; }

    /// <summary>
    /// The Type of the label
    /// </summary>
    [DataMember(EmitDefaultValue = false)]
    public virtual LabelType Type { get; set; }

    [DataMember(EmitDefaultValue = false)]
    public virtual ResultLine ResultLine { get; set; }
}
Was it helpful?

Solution 2

It turns out that my problem was almost completely unrelated to the information I had given. I am using NHibernate, and on this occasion I had forgotten to Detach the object before passing it in my callback. This is the actual error (found with svclog):

Type 'LocationProxy' with data contract name 'LocationProxy:http://schemas.datacontract.org/2004/07/' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'

WCF was complaining about the magic NHibernate properties that had been added when I attached the label to the object graph.

OTHER TIPS

I suppose one or more classes are not ready for serialization yet.

You might need to mark the classes with the [DataContract] attribute and all members that need to be send through the wire mith the [DataMember] attribut

Like this:

[DataContract]
public class PurchaseOrder
{
    [DataMember]
    public Address BillTo {get; set;}
    [DataMember]
    public Address ShipTo {get; set;};
}

Have a look at this MSDN article: Serialization and Deserialization

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top