gpt4 book ai didi

c# - 如何解决此 WCF 异常?

转载 作者:行者123 更新时间:2023-11-30 13:05:57 25 4
gpt4 key购买 nike

我在使用 WCF 服务时遇到问题。返回类型是一个半复杂类型,它引用各种基本类型和每个类型继承的基接口(interface)。

在我的调试中,序列化消息的总字节大小远低于默认的 65535 字节阈值。尽管如此,我已将 maxReceivedMessageSize 属性增加到 1000000,问题仍然存在。

WCF服务定义如下:

[ServiceContract]
public interface ILoggingService
{
[OperationContract]
NotesInfo ListNotes(NotesQueryOptions options);
}

这是 NotesInfo 返回对象的定义:

[DataContract]
public class NotesInfo
{
[DataMember] public List<TokenizedNote> Notes { get; set; }
[DataMember] public Dictionary<long, User> Users { get; set; }
[DataMember] public Dictionary<long, NoteCategory> NoteCategories { get; set; }
[DataMember] public Dictionary<string, Dictionary<long, IIdentifiable<long>>> EntitiesByToken { get; set; }
}

当我尝试调用该服务时,抛出了以下异常:

The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ServiceModel.CommunicationException: The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.

Source Error:

Line 242:
Line 243: public AxeFrog.Mobile.NotesInfo ListNotes(AxeFrog.Mobile.NotesQueryOptions options) {
Line 244: return base.Channel.ListNotes(options);
Line 245: }
Line 246: }

Source File: C:\Users\Nathan\Work\Internal Projects\AxeFrog System\Source\Trunk\AxeFrog.Mobile.WebInterface\Service References\LoggingServiceReference\Reference.cs Line: 244

以下是涉及的其他实体的代码:

public interface IIdentifiable<TID>
{
TID ID { get; set; }
}

[DataContract]
public class Note : IIdentifiable<long>
{
[DataMember] public long ID { get; set; }
[DataMember] public DateTime DateStamp { get; set; }
[DataMember] public long? UserID { get; set; }
[DataMember] public long NoteCategoryID { get; set; }
[DataMember] public NoteType NoteType { get; set; }
[DataMember] public string Message { get; set; }
}

public enum NoteType
{
Information = 0,
Warning = 10,
Failure = 20
}

[DataContract]
public class NoteCategory : IIdentifiable<long>
{
[DataMember] public long ID { get; set; }
[DataMember] public string Name { get; set; }
}

[DataContract]
public class NoteEntityType : IIdentifiable<long>
{
[DataMember] public long ID { get; set; }
[DataMember] public Type TypeName { get; set; }
}

[DataContract]
public class TokenizedNote
{
[DataMember] public Note Note { get; set; }
[DataMember] public List<NoteSegment> NoteSegments { get; set; }
}

public abstract class NoteSegment
{
public abstract string Render(INoteRenderer renderer, Dictionary<string, Dictionary<long, IIdentifiable<long>>> entitiesByToken);
}

[DataContract]
public class NoteTextSegment : NoteSegment
{
[DataMember]
public string Text { get; set; }
}

[DataContract]
public class NoteEntitySegment : NoteSegment
{
[DataMember] public long EntityID { get; set; }
[DataMember] public string Token { get; set; }
}

请注意,为了便于阅读,我已经从 NoteSegment 的抽象实现中删除了 Render() 覆盖。

以下是来自调试器的一些信息,因此您可以查看返回的内容:

alt text alt text

任何对我在这里可能做错了什么的见解都将不胜感激。 Google 搜索几乎找不到有用的答案。

最佳答案

你在客户端显示异常;当您在服务器上附加调试器(或打开日志记录)时会发生什么,在那里看到任何有用的东西?

关于c# - 如何解决此 WCF 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1389057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com