The error code is absolutely terrible, ERR_CONNECTION_RESET has a host of causes and the causes that I found on other questions were related to having too small of a MaxRequestLength for large web service calls. The data I was returning was only a couple of kB though, so this couldn't be the issue.
Here is my interface code
[WebGet(RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "GetReportByID?ReportID={ReportID}")]
[OperationContract]
UsageReport GetReportByID(int ReportID);
This was the implementation
public UsageReport GetReportByID(int ReportID)
{
return new UsageReport(ReportID);
}
And this was the class code for UsageReport
[DataContract]
public class UsageReport
{
[DataMember]
List<UsageItem> RL;
public UsageReport(int reportID)
{
RL = new List<UsageItem>();
using (SqlDataReader dr = DBUtility.ExecuteReader(cmd, "DBString"))
{
while (dr.Read())
{
ItemNumber = dr["ItemID"] as int? ?? 0;
RL.Add(new UsageItem(ItemNumber));
}
dr.Close();
}
}
public class UsageItem
{
int ItemNumber;
public UsageItem(int ItemNumber)
{
this.ItemNumber = ItemNumber;
}
}
The problem was my UsageItem class, I was missing the necessary DataContract and DataMember fields.
[DataContract]
public class UsageItem
{
[DataMember]
int ItemNumber;
public UsageItem(int ItemNumber)
{
this.ItemNumber = ItemNumber;
}
}
I'd like to add a solution related to a case where WCF is used on the server side:
Add diagnostics
to web.config
(taken from here):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.Net" switchValue="Verbose">
<listeners>
<add name="SystemNetTrace"/>
</listeners>
</source>
<source name="System.ServiceModel" switchValue="Verbose, ActivityTracing" propagateActivity="true">
<listeners>
<add name="wcftrace" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Verbose, ActivityTracing">
<listeners>
<add name="wcfmessages" />
</listeners>
</source>
<source name="System.Runtime.Serialization" switchValue="Verbose">
<listeners>
<add name="wcfmessages" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="SystemNetTrace" type="System.Diagnostics.TextWriterTraceListener" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, Callstack" initializeData="C:\Traces\System_Net.txt" />
<add name="wcftrace" type="System.Diagnostics.XmlWriterTraceListener" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, Callstack" initializeData="C:\Traces\WCFTrace.svclog" />
<add name="wcfmessages" type="System.Diagnostics.XmlWriterTraceListener" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, Callstack" initializeData="C:\Traces\WCFMessages.svclog" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
</configuration>
Reproduce the error, then go to the trace folder (C:\Traces
, in this example). There will be 2 svclog
files there: WCFMessages.svclog
and WCFTrace.svclog
.
Open the file named WCFMessages.svclog
. A "Microsoft Service Trace Viewer" window will open, showing errors with a red color.
If no errors are displayed, open WCFTrace.svclog
, and the errors (in red) would be there.
System.Runtime.Serialization
error because of a lack of DataContract
attribute.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With