2016-06-14 5 views
3

Ich habe gerade begonnen, mit WCF zu arbeiten und konfrontiert mit einem Problem, das ich nicht behandeln kann. Ich habe einen Code wie unten.WCF und Datenvertrag mit Vorlage

Daten

[DataContract] 
public class DataValue<T> 
{ 
    [DataMember] public string Name  { get; set; } 
    [DataMember] public T Value   { get; set; } 
} 

[DataContract] 
public class Point : DataValue<float> 
{ 
    public override string ToString() => $"{Name}\t\t{Value:F2}"; 
} 

und Service

[ServiceContract(SessionMode=SessionMode.Required, CallbackContract = typeof(IServiceCallback))] 
[ServiceKnownType(typeof(Point))] 
public interface IService 
{ 
    [OperationContract] 
    Point[] GetPoints(); 
} 

public sealed class Service : IService 
{ 
    public Point[] GetPoints() 
    { 
     var p = new [] { new Point { Name = "point_1", Value = 1.1F } }; 
     return p; 
    } 
} 

Wenn ich versuche, GetPoints auf Client-Seite aufrufen erhalte ich eine Ausnahme

Unhandled Exception: System.ServiceModel.CommunicationException: Error in deserializing body of reply message for operation 'GetPoints'. Unexpected end of file. 
Following elements are not closed: Envelope. ---> System.Xml.XmlException: Unexpected end of file. Following elements are not closed: Envelope. 
    at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3) 
    at System.Xml.XmlExceptionHelper.ThrowUnexpectedEndOfFile(XmlDictionaryReader reader) 
    at System.Xml.XmlBaseReader.MoveToEndOfFile() 
    at System.Xml.XmlBinaryReader.ReadNode() 
    at System.Xml.XmlBinaryReader.Read() 
    at System.Xml.XmlBaseReader.ReadEndElement() 
    at System.ServiceModel.Channels.Message.ReadFromBodyContentsToEnd(XmlDictionaryReader reader, EnvelopeVersion envelopeVersion) 
    at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest) 
    at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters) 
    --- End of inner exception stack trace --- 

Server stack trace: 
    at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters) 
    at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc&rpc) 
    at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) 
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 

Es ist wie eine Art von Serialisierung Problem scheint, Ich habe versucht, Netto-TCP-Bindungspuffer zu erhöhen (MaxBufferSize, MaxReceivedMessageSize), aber es tut nicht helfen. Gibt es Ideen, wie das zu beheben ist?

Antwort

1

Wenn dieser Fehler zwischen einer NET und mono auftritt, dann verursacht sein wahrscheinlichen diese NetTcpBinding Umsetzung des wcf mono bug

Mono/wurde falsch ist ein Feld mit variabler Länge codiert. Das bedeutet, dass für einen .net-Client einige Interface-Methodenaufrufe funktionieren, während andere den Fehler "Folgende Elemente sind nicht geschlossen: Envelope" auslösen, während die Antwort von mono verarbeitet wird.

+0

Fixed mit https://github.com/mono/mono/pull/5842 – vinogradniy

Verwandte Themen