WCF和带模板的数据契约
我刚刚开始与WCF合作,面临一个我无法处理的问题。我有一些代码如下 资料 当我试图在客户端调用GetPoints时,我得到一个异常WCF和带模板的数据契约,wcf,datacontract,Wcf,Datacontract,我刚刚开始与WCF合作,面临一个我无法处理的问题。我有一些代码如下 资料 当我试图在客户端调用GetPoints时,我得到一个异常 Unhandled Exception: System.ServiceModel.CommunicationException: Error in deserializing body of reply message for operation 'GetPoints'. Unexpected end of file. Following elements are
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)
这似乎是某种序列化问题,我试图增加网络tcp绑定缓冲区(MaxBufferSize、MaxReceivedMessageSize),但没有帮助。有没有办法解决这个问题?如果这个错误发生在.net和mono之间,那么它很可能是由这个错误引起的 Mono的nettcpbinding实现错误地编码了可变长度字段。这意味着,对于.net客户机,在处理mono的响应时,某些接口方法调用将起作用,而其他接口方法调用将抛出“以下元素未关闭:信封”错误
[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;
}
}
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)