Raven returning 400 "Request Too Long" error when NServiceBus tries to schedule a timeout - ravendb

I have an NServiceBus saga that is trying to schedule a timeout using the Raven timeout persister but when it tries it gets this error:
NServiceBus.Unicast.Transport.Transactional.TransactionalTransport [(null)] <(null)> - Failed raising 'transport message received' event for message with ID=90dadfbd-9eb6-4558-96ec-37edb642330a\17275422
System.InvalidOperationException: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Request Too Long</h2>
<hr><p>HTTP Error 400. The size of the request headers is too long.</p>
</BODY></HTML>
---> System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.GetResponse()
at Raven.Client.Connection.HttpJsonRequest.ReadStringInternal(Func`1 getResponse)
--- End of inner exception stack trace ---
at Raven.Client.Connection.HttpJsonRequest.ReadStringInternal(Func`1 getResponse)
at Raven.Client.Connection.HttpJsonRequest.ReadResponseString()
at Raven.Client.Connection.HttpJsonRequest.ReadResponseJson()
at Raven.Client.Connection.ServerClient.DirectPut(RavenJObject metadata, String key, Nullable`1 etag, RavenJObject document, String operationUrl)
at Raven.Client.Connection.ServerClient.<>c__DisplayClass10.<Put>b__f(String u)
at Raven.Client.Connection.ServerClient.TryOperation[T](Func`2 operation, String operationUrl, Boolean avoidThrowing, T& result)
at Raven.Client.Connection.ServerClient.ExecuteWithReplication[T](String method, Func`2 operation)
at Raven.Client.Connection.ServerClient.Put(String key, Nullable`1 etag, RavenJObject document, RavenJObject metadata)
at Raven.Client.Document.HiLoKeyGenerator.PutDocument(JsonDocument document)
at Raven.Client.Document.HiLoKeyGenerator.GetNextMax()
at Raven.Client.Document.HiLoKeyGenerator.NextId()
at Raven.Client.Document.HiLoKeyGenerator.GenerateDocumentKey(DocumentConvention convention, Object entity)
at Raven.Client.Document.MultiTypeHiLoKeyGenerator.GenerateDocumentKey(DocumentConvention conventions, Object entity)
at Raven.Client.Document.DocumentStore.<>c__DisplayClass1.<Initialize>b__0(Object entity)
at Raven.Client.Document.InMemoryDocumentSessionOperations.GetOrGenerateDocumentKey(Object entity)
at Raven.Client.Document.InMemoryDocumentSessionOperations.StoreInternal(Object entity, Nullable`1 etag, String id)
at Raven.Client.Document.InMemoryDocumentSessionOperations.Store(Object entity)
at NServiceBus.Timeout.Hosting.Windows.Persistence.RavenTimeoutPersistence.Add(TimeoutData timeout)
at NServiceBus.Timeout.Core.TimeoutTransportMessageHandler.Handle(TransportMessage message)
at NServiceBus.Unicast.Transport.Transactional.TransactionalTransport.OnTransportMessageReceived(TransportMessage msg)
I have restarted the Raven service & the nservicebus host. I've tried recreating this saga again but it still happens.
The timeout status message that is being scheduled is tiny:
<Messages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.net/Invoicing.Service">
<IPartPaymentTimeout>
<Amount>10.00</Amount>
<OriginalTransactionTimeUtc>2013-01-14T05:49:04.8180938Z</OriginalTransactionTimeUtc>
<PaymentNumber>7</PaymentNumber>
<Id>123456</Id>
<InvoiceNumber>1234567/34567</InvoiceNumber>
</IPartPaymentTimeout>
</Messages>

This was resolved in my case by stopping New Relic from instumenting custom applications. It looks like there is a bug in New Relic where it appends a request header X-NewRelic-ID, which gets appended with the same data until it grows too long:
X-NewRelic-ID: <hash>, <samehash>, <samehash>,.....<samehash>
Disabling instrumentation of NServiceBus.Host in the NewRelic.xml file prevents the header being sent.
In NewRelic.xml, you might also disable crossApplicationTracingEnabled.
To detect this, use tracing from System.Diagnostics:
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.Net" maxdatasize="1024">
<listeners>
<add name="MyTraceFile"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add
name="MyTraceFile"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="System.Net.trace.log"
/>
</sharedListeners>
<switches>
<add name="System.Net" value="Verbose" />
</switches>

Related

WCF IClientMessageInspector Logging Discrepancy Regarding Action

I am logging outgoing WCF Soap requests from my application, and discovered a discrepancy between what I'm logging and what actually goes out to the server via the wire.
Here is what I'm logging:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/myinterface</Action>
</s:Header>
<s:Body>
<myinterface xmlns="http://tempuri.org/">
...
Here is what actually goes out (captured with WireShark):
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<myinterface xmlns="http://tempuri.org/">
...
You'll notice that the WireShark capture does not have the Header or Action elements.
I only noticed this because I tried pushing my logged request out through SoapUI.
I'm using this code to log the request:
public class InspectorBehavior : IEndpointBehavior
{
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
clientRuntime.MessageInspectors.Add(new WCFMessageInspector());
}
And:
public class WCFMessageInspector : IClientMessageInspector
{
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
{
Log(request.ToString());
return null;
}
And:
client.Endpoint.Address = new System.ServiceModel.EndpointAddress(address);
client.Endpoint.Behaviors.Add(new InspectorBehavior());
Does anyone know if there's a way to capture exactly what is going out (verbatim), without any post-processing as shown above?
You can configure WCF Message Logging in your App.config to log messages at transport level.
This should capture the message as late as possible:
For outgoing messages, logging happens immediately after the message leaves user code and immediately before the message goes on the wire.
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="messages"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="c:\logs\messages.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.serviceModel>
<diagnostics>
<messageLogging
logEntireMessage="true"
logMalformedMessages="true"
logMessagesAtServiceLevel="false"
logMessagesAtTransportLevel="true"
maxMessagesToLog="1000"
maxSizeOfMessageToLog="1000000"/>
</diagnostics>
</system.serviceModel>
You can capture exact content via custom MessageEncoder, unlike message inspectors (IDispatchMessageInspector / IClientMessageInspector) it sees original byte content including any malformed XML data.
However it's a bit harder to implement this approach. You have to wrap a standard textMessageEncoding as custom binding element and adjust config file to use that custom binding.
Also you can see as example how I did it in my project - wrapping textMessageEncoding, logging encoder, custom binding element and config.

WCF Rest Service broken after server restart

I made a WCF Rest Service and attached it to IIS 7 on my server and it worked great. Suddenly, we had a hard drive failure and the guys who're supposed to manage the backups didn't back up anything, so we lost all our stuff on the server.
So I go about setting everything back up, and I put all the stuff on IIS. We have another WCF Rest Service that does a lot of stuff the one I made does, including a couple of the same methods for authentication and such. But now it seems that mine won't work. Our website works and our other web service works, but not this one, and I've no idea why? I set them up the exact same and I don't think I changed anything when I did it initially.
The help reference pages work, but when calling the method, I get
"The server encountered an error processing the request. Please see the service help page for constructing valid requests to the service."
I'm using the same methods as before, calling them with the same arguments, this happens for every method, regardless of GET or POST. I've used a REST extension thing in chrome to call it and the mobile app that I usually use to call it, as well as the browser and they all come up with the same error.
Here's the web.config file for it (I've tried adding a few things found on stackoverflow to get to the problem, but it's not done anything, really).
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.serviceModel >
<behaviors>
<serviceBehaviors>
<behavior name="DataServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings >
<!-- pick whichever binding you want .... -->
<basicHttpBinding>
<!-- binding configuration with a name -->
<binding name="ExtendedMaxSize"
maxBufferSize="52428800" maxReceivedMessageSize="52428800" >
<readerQuotas maxDepth="52428800" maxStringContentLength="52428800"
maxArrayLength="52428800" maxBytesPerRead="52428800" maxNameTableCharCount="52428800" />
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" defaultOutgoingResponseFormat="Json" crossDomainScriptAccessEnabled="true" maxReceivedMessageSize="52428800" maxBufferSize="52428800" maxBufferPoolSize="52428800" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
</configuration>
After turning tracing on, got this error from the viewer:
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System
xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131076</EventID><Type>3</Type><SubType Name="Error">0</SubType><Level>2</Level><TimeCreated SystemTime="2014-03-27T12:15:47.5749853Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{54672f7e-5a71-4dda-92a3-f07f7c94ccb9}" /><Execution ProcessName="w3wp" ProcessID="20820" ThreadID="9" /><Channel /><Computer>OHS-VMHOST-NEW</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord Severity="Error" Channel="Operational" xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"><TraceIdentifier>http://msdn.microsoft.com/en-GB/library/System.ServiceModel.Diagnostics.TraceHandledException.aspx</TraceIdentifier><Description>Handling an exception. Exception details: System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
at System.Guid.GuidResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument, String failureArgumentName, Exception innerException)
at System.Guid.TryParseGuidWithNoStyle(String guidString, GuidResult& result)
at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result)
at System.Guid..ctor(String g)
at OHS.MobileAssessor.Services.MobileAssessorAPIService.GetProjectData(String token)
at SyncInvokeGetProjectData(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</Description><AppDomain>/LM/W3SVC/1/ROOT/mobileassessor-1-130403961472161807</AppDomain><Exception><ExceptionType>System.FormatException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).</Message><StackTrace> at System.Guid.GuidResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument, String failureArgumentName, Exception innerException)
at System.Guid.TryParseGuidWithNoStyle(String guidString, GuidResult&amp; result)
at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult&amp; result)
at System.Guid..ctor(String g)
at OHS.MobileAssessor.Services.MobileAssessorAPIService.GetProjectData(String token)
at SyncInvokeGetProjectData(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp; outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace><ExceptionString>System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
at System.Guid.GuidResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument, String failureArgumentName, Exception innerException)
at System.Guid.TryParseGuidWithNoStyle(String guidString, GuidResult&amp; result)
at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult&amp; result)
at System.Guid..ctor(String g)
at OHS.MobileAssessor.Services.MobileAssessorAPIService.GetProjectData(String token)
at SyncInvokeGetProjectData(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp; outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</ExceptionString></Exception></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent>
As requested, my GetProjectData method (And no, it isn't managing to write anything to my event log):
/// <summary>
///
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
[WebGet(UriTemplate = "GetProjectData/{token}", ResponseFormat = WebMessageFormat.Json)]
public GetProjectContainerResult GetProjectData(string token)
{
WriteLog("Getting project data...");
GetProjectContainerResult result = new GetProjectContainerResult();
ProjectContainer container = new ProjectContainer();
MobileAssessorAuthenticationResults authResult = ValidateToken(new Guid(token));
if (authResult == MobileAssessorAuthenticationResults.Success)
{
container.jobs = getJobs(token);
container.buildings = getBuildings();
container.floors = getFloors();
container.locations = getLocations();
result.ReturnValue = container;
result.Result = MobileAssessorOperationResults.Success;
}
else
{
switch (authResult)
{
case MobileAssessorAuthenticationResults.Error:
result.Result = MobileAssessorOperationResults.Error;
result.ResultDescription = "An error occured.";
result.ReturnValue = new ProjectContainer();
break;
case MobileAssessorAuthenticationResults.Expired:
result.Result = MobileAssessorOperationResults.Failed;
result.ResultDescription = "The specified token has expired.";
result.ReturnValue = new ProjectContainer();
break;
case MobileAssessorAuthenticationResults.Invalid:
result.Result = MobileAssessorOperationResults.Failed;
result.ResultDescription = "The specified token is not valid.";
result.ReturnValue = new ProjectContainer();
break;
}
}
return result;
}
Looking at the stack trace from your log, I think you are having issues parsing a GUID in MobileAssessorAPIService.GetProjectData method
at System.Guid.TryParseGuidWithNoStyle(String guidString, GuidResult&amp; result)
at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult&amp; result)
at System.Guid..ctor(String g)
at OHS.MobileAssessor.Services.MobileAssessorAPIService.GetProjectData(String token)
I would recommend that you put a break point in this method and attach a debugger to your REST service.
Based on the code you posted, the suspected line is
MobileAssessorAuthenticationResults authResult = ValidateToken(new Guid(token));
if you are not able to remotely debug this, I would recommend that you add logging just before this line to log the value of token. something like
logger.Log("paramater token = " + token);
Alternately, use wireshark to check the value of the token. once you extract the value of that guid, validate it online at http://guid.us/Test/GUID

wcf linq to sql error

I am getting an error returning a linq query over http to an ASP.Net application
I have the following wcf service running in IIS
public class ProductService : IProductService
{
NorthwindEntities context = new NorthwindEntities();
public List<Customer> GetCustomers()
{
return context.Customers.Select(c => c).ToList();
}
}
Web Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<services>
<service name="WCF_Entity.ProductService">
<endpoint address="" binding="wsHttpBinding" contract="WCF_Entity.IProductService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<connectionStrings>
<add name="NorthwindEntities" connectionString="metadata=res://*/Northwind.csdl|res://*/Northwind.ssdl|res://*/Northwind.msl;provider=System.Data.SqlClient;provider connection string="Data Source=SHLOMOKATZ-PC;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
I created a ASP.Net application to use the service
myService.ProductServiceClient objService = new ProductServiceClient();
var customers = objService.GetCustomers();
on debuging, I get the following error
An existing connection was forcibly closed by the remote host
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.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
Source Error:
Line 2454:
Line 2455: public ASPWFC.myService.Customer[] GetCustomers() {
Line 2456: return base.Channel.GetCustomers();
Line 2457: }
Line 2458: }
Source File: D:\My Documents\Visual Studio 2010\Projects\wcf\WCF_Entity\ASPWFC\Service References\myService\Reference.cs Line: 2456
Stack Trace:
[SocketException (0x2746): An existing connection was forcibly closed by the remote host]
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +6132200
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +134
[IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.]
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +300
System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) +26
System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) +265
[WebException: The underlying connection was closed: An unexpected error occurred on a receive.]
System.Net.HttpWebRequest.GetResponse() +6038435
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +103
[CommunicationException: An error occurred while receiving the HTTP response to http://localhost/WCF_Entity_SVC/ProductService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9464367
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
ASPWFC.myService.IProductService.GetCustomers() +0
ASPWFC.myService.ProductServiceClient.GetCustomers() in D:\My Documents\Visual Studio 2010\Projects\wcf\WCF_Entity\ASPWFC\Service References\myService\Reference.cs:2456
ASPWFC._Default.Page_Load(Object sender, EventArgs e) in D:\My Documents\Visual Studio 2010\Projects\wcf\WCF_Entity\ASPWFC\Default.aspx.cs:36
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +37
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +95
System.Web.UI.Control.OnLoad(EventArgs e) +145
System.Web.UI.Control.LoadRecursive() +134
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3412
changing the buffer length, etc... Didn't solve the issue. The database is the sample NorthWind database
I am able to browse to the service
It seems that Aliostad is correct as I recreated the service without using IIs and used ASP to consume the service, and get the below error. So it is a problem invoking the svc from the app, I can still run the service directly via http
The underlying connection was closed: The connection was closed unexpectedly.
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.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly.
Source Error:
Line 2337:
Line 2338: public NorthwindApp.myService.Customer[] getCustomers() {
Line 2339: return base.Channel.getCustomers();
Line 2340: }
Line 2341: }
Source File: d:\my documents\visual studio 2010\Projects\wcf\NorthwindServices\NorthwindApp\Service References\myService\Reference.cs Line: 2339
Stack Trace:
[WebException: The underlying connection was closed: The connection was closed unexpectedly.]
System.Net.HttpWebRequest.GetResponse() +6038435
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +51
[CommunicationException: The underlying connection was closed: The connection was closed unexpectedly.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9464367
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
NorthwindApp.myService.INorthwindService.getCustomers() +0
NorthwindApp.myService.NorthwindServiceClient.getCustomers() in d:\my documents\visual studio 2010\Projects\wcf\NorthwindServices\NorthwindApp\Service References\myService\Reference.cs:2339
NorthwindApp._Default.Page_Load(Object sender, EventArgs e) in d:\my documents\visual studio 2010\Projects\wcf\NorthwindServices\NorthwindApp\Default.aspx.cs:18
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +46
System.Web.UI.Control.OnLoad(EventArgs e) +83
System.Web.UI.Control.LoadRecursive() +120
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3954
I found an article that says that with entity framework 4 there is a problem to serialize entities in wcf with lazy loading enabled
I added the following code to the service and everything works
context.ContextOptions.LazyLoadingEnabled = false;
link to article http://geekswithblogs.net/danemorgridge/archive/2010/05/04/entity-framework-4-wcf-amp-lazy-loading-tip.aspx
How many records are being returned? There are a couple of things in play here:
From a WCF Perspective:
MaxBufferSize: Gets or sets the maximum size of the buffer to use. For buffered messages this value is the same as MaxReceivedMessageSize. For streamed messages, this value is the maximum size of the SOAP headers, which must be read in buffered mode. For a non-streamed message, if the message size is greater than this property, then the message is dropped.
If not specified, this defaults to 65536.
This is only 0.0625 megabytes!
MaxReceivedMessageSize: Gets and sets the maximum allowable message size that can be received.
Default here is also 65536 bytes.
MaxStringContentLength: Gets and sets the maximum string length returned by the reader.
Your service is probably returning a value greater in size than the defaults.
So, you could try modifying your service behavior to include these attributes with higher limits, say 6 MB or so to see if it resolves your issue.
Also - remember there is maxRequestLength limit which is enforced by IIS which trumps any WCF setting, the default is 4096 KB, so you may have to tweak that if you alter the above properties.

WCF call causing memory leak

We are having problems with a WCF services call that is leaking memory. In our research we think we are calling the service correctly and handling errors that come back from it appropriately. We have even confirmed this with MSDN articles and sample WCF code obtained from a MS web site.
Here is a sample of the code that causes the leak. On the SaveAssociation call, the code on the other side throws an exception. This causes the channel to enter the faulted state. The first catch statement catches the exception (SystemException) and calls Abort() on the client which should immediately abort the session and close the client connection. However, watching this process run this code over and over in a loop we just see the memory used by the process climb and climb.
var client = new FrameworkServiceReference.MAServiceClient();
// Get User domain name
client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password = "password";
OperationContextScope a1 = new OperationContextScope(client.InnerChannel);
MessageHeader<string> customHeaderAppID = new MessageHeader<string>("Account Management");
System.ServiceModel.Channels.MessageHeader a2 = customHeaderAppID.GetUntypedHeader("application", "http://www.ma.com");
OperationContext.Current.OutgoingMessageHeaders.Add(a2);
try
{
client.SaveAssociation(association);
client.Close();
}
catch (SystemException se)
{
client.Abort();
}
catch (Exception ex)
{
client.Abort();
}
Here is the error we receiveā€¦
System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Object reference not set to an instance of an object. (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.NullReferenceException: Object reference not set to an instance of an object.
at Multiview.Business.Core.CoreObject.ValidateItem(String Item, String Value)
at Multiview.Business.Core.User.UpdateUser()
at Multiview.Business.Core.User.Save()
at Multiview.Core.ServiceLibrary.MultiviewService.SaveCRMUser(User user, Guid CRMGuid)
at SyncInvokeSaveCRMUser(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceMode...).
What can be done to stop this leak?
If memory on the server goes up, check the server log. Probably the object you return has a circular reference. This means that when it is returned, the server will throw a stack overflow when serializing the object.
Try to configure your service with:
IncludeExceptionDetailInFaults=true
And create some logs (server and client side):
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Error, ActivityTracing" propagateActivity="true">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="CardSpace">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.IO.Log">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.Runtime.Serialization">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.IdentityModel">
<listeners>
<add name="xml" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\t\mylog.svclog" />
</sharedListeners>
</system.diagnostics>
If you have a problem with memory leaks you should start with some memory profiler and find which objects are living in your memory. That will lead you to the source of leakage.
You can start with the fact that OperationContextScope is disposable.

WCF tracing & message logging - trace level warning

Assume I have a config file which looks like this:
...
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Warning,ActivityTracing" propagateActivity="true">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="LogServer.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="ServiceModelTraceListener" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
When using this config file every activity the caller performs against the service and each corresponding message that's sent to the service will be logged in the svclog file. Everything fine so far.
If I modify the 3rd line from the above listing to <source name="System.ServiceModel" switchValue="Warning" propagateActivity="true"> (the ActivityTracing is removed) then only those activities are logged that are at least labeled level warning. But it's still every message logged...
So is there a way to only log those message that correspond to those activities that are at least warnings? Those messages that succeeded aren't very interesting in that moment, but those messages that belong to the unsuccessful activities are!
Edit
To filter messages beyond the options below you may want to look into writing your own TraceSource.
Below is one I am using for a project. You could easily customize it to filter out the messages you want or perhaps hide activity if it is not in DEBUG, etc.
class DB : TraceSource
{
public DB(string name) : base(name)
{
}
public DB(string name, SourceLevels sourceLevels) : base (name, sourceLevels)
{
}
public void Log(object value)
{
WriteLine(value);
}
public void Error(object value)
{
WriteLine(value, TraceEventType.Error);
}
public void Error(RecordingResponseData errorResponse)
{
string errorMessage = "[Error] Code: "+errorResponse.ErrorCode +" Message: "+errorResponse.ErrorMessage;
WriteLine(errorMessage, TraceEventType.Error);
}
public void Warn(object value)
{
WriteLine(value, TraceEventType.Warning);
}
public void WriteLine(object value, TraceEventType type = TraceEventType.Information)
{
TraceEvent(type, 0, value.ToString());
}
}
Original
Your options are:
Critical
Error
Warning
Information
ActivityTracing
Verbose
All
Or a combination there of. If you have it set to Warning but are still getting too many messages then you may want to try Error or Critical.
ref: https://msdn.microsoft.com/en-us/library/ms733025%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
There's a switchValue available for the System.ServiceModel.MessageLogging trace switch as well. Just add that attribe to that source element and set it to Warning also and you will only see messages logged that are related to warnings.
Get rid of System.ServiceModel.MessageLogging source to get rid of logging messages to resolve "still every message logged".