How to eliminate this WCF exception?

I'm having problems with the WCF service. The return type is a semi-complex type that refers to the various base types and the base interface that each of these types inherits from.

In my debugging, the total byte size of the serialized message is under the default threshold of 65535 bytes. However, I increased the maxReceivedMessageSize attribute to 1,000,000, and the problem remains.

The WCF service is defined as follows:

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

Here is the definition for the returned NotesInfo object:

 [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; } } 

When I try to call a service, I get the following exception:

The server did not provide a meaningful response; this may be caused by non-compliance with the contract, premature session termination or internal server error. Description: An unhandled exception occurred during the execution of the current web request. Look at the stack trace for error information and it came from the code.

Exception Details: System.ServiceModel.CommunicationException: The server did not provide a meaningful response; this may be caused by non-compliance with the contract, premature session termination or 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 Links \ LoggingServiceReference \ Reference.cs Line: 244

Below is the code for the other objects involved:

 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; } } 

Note that I removed the Render () overrides from the abstract NoteSegment implementations for readability.

Here is some info from thedebugger so you can see what is coming back:

alt textalt text

Any understanding of what I might be doing wrong would be appreciated. A Google search provides few answers to useful answers.

+4
source share
6 answers

You show an exception on the client; what happens when you attach a debugger on the server (or turn on logging), do you see anything useful there?

0
source

This may be caused by the message too long. You should try to change the limits by editing your app.config as follows:

 <binding name="WebBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
0
source

Could it be that your server has been going to collect the answer for too long? By default, "sendTimeout" on the client is only 60 seconds - you can try to increase it to something larger:

 <binding name="TweakedBinding" sendTimeout="120" /> 

What does your client config look like? What binding are you using? What are the security settings?

Mark

UPDATE:
could you add the debugging behavior of the service to your service so that you can get more debugging information and a client-side error when something went wrong?

 <behaviors> <serviceBehavior> <behavior name="YourBehaviorName"> <serviceDebug includeExceptionDetailInFaults="True" /> </behavior> </serviceBehavior> </behaviors> 
0
source

This question is out of date, but I will drop it there if someone finds it useful. My guess about what happens here is an inheritance from NoteSegment - you will need to use the KnownType attribute to tell the TokenizedNote object that it can expect NoteTextSegment and NoteEntitySegment when it deserializes (since by default it will only expect an instance of NoteSegment).

 [DataContract] [KnownType(typeof(NoteEntitySegment)] [KnownType(typeof(NoteTextSegment)] public class TokenizedNote { [DataMember] public Note Note { get; set; } [DataMember] public List<NoteSegment> NoteSegments { get; set; } } 

See this resource for more details: http://msdn.microsoft.com/en-us/library/ms730167(v=vs.110).aspx

0
source

I had a similar problem. After I spent 2 hours thinking about it and trying to find an answer on the Internet, I decided to follow the approach to serialize and deserialize the return value / object on the server side using System.Runtime.Serialization.DataContractSerializer and finally found that I missed adding the EnumMember attribute to one of Enums.

Here is a piece of code that helped me solve the problem:

  var dataContractSerializer = new System.Runtime.Serialization.DataContractSerializer(typeof(MyObject)); byte[] serializedBytes; using (System.IO.MemoryStream mem1 = new System.IO.MemoryStream()) { dataContractSerializer.WriteObject(mem1, results); serializedBytes = mem1.ToArray(); } MyObject deserializedResult; using (System.IO.MemoryStream mem2 = new System.IO.MemoryStream(serializedBytes)) { deserializedResult = (MyObject)dataContractSerializer.ReadObject(mem2); } 
0
source

Open IIS, select a site, click "Basic Settings", then click "Test Settings." What I missed is that the site needs valid credentials, as well as its application pool.

0
source

All Articles