Uploading a file to REST WCF service connection forcibly closed issue - wcf

I have WCF websrvice Hosted on IIS 7.5 and IIS8, and I'm suing a REST endpoint to communicate to web service from my web application.
I'm using httpWebrequest to upload a file and I have set each and every setting possible in web.config of both sides to make sure asp.net will let me upload large files.
Its working fine with large files in IIS 8 but in IIS 7.5 I get the following Error:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 10/02/2014 4:04:39 PM
Event time (UTC): 10/02/2014 6:04:39 AM
Event ID: 8aea1d07d67743ba81a4c46bcd622ed1
Event sequence: 63
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/1/ROOT/OP.Web-1-130364857480032265
Trust level: Full
Process information:
Process ID: 5320
Process name: w3wp.exe
Account name: IIS APPPOOL\MyApplication AppPool
Exception information:
Exception type: IOException
Exception message: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
I would be thankful if you help me with this issue.

There are two different places where request size can be specified in IIS, as explained
in this answer. Maybe additional places within the WFC architecture also. But all of them are limited to 4GB (or 2GB in some cases). In one of our implementations, we found the best route to be that we host a custom Owin based web server to specifically handle uploaded requests. It takes a few lines of code to get that up and running, and there are samples available on asp.net website.

Related

Example of a .Net6 Blazor WebAssembly application with authentication using local Sql Db?

I'm trying to add authentication (with registration, password reset etc) to a .Net6 Blazor WebAssembly project. When creating the project include authentication for individual accounts (to local sql db), configure for HTTPS, Asp.Net Core hosted and Progressive Web Application. This is done in VS 2022.
The problem I'm facing is that each project I've created so far continues to crash as soon as I try to register or login.
similar to this thread: Blazor WebAssembly Hosted Proxy crash on successful authentication
I also looked at the link to https://github.com/dotnet/aspnetcore/issues/26635 but the issue was resolved. I'm currently running Chrome Version 99.0.4844.82 (Official Build) (64-bit).
I tried removing the autocomplete attribute on the server side cshtml pages but the project still random crashes.
Has anyone successfully implemented authentication (using local Sql) in a webAssebly project with .Net6?
I also tried to run the samples from the .NetCore git repo and the apps continue to crash.
This is the server console output:
fail: Microsoft.WebAssembly.Diagnostics.DevToolsProxy[0] DevToolsProxy::Run: Exception System.AggregateException: One or more errors occurred. (The remote party closed the WebSocket connection without completing the close handshake.) ---> System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake. ---> System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request. at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitableEventArgs.g__ThrowSocketException|5_0(SocketError e) at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitableEventArgs.GetResult(Int16 token) at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.DoReceive() at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result) at System.IO.Pipelines.Pipe.GetReadAsyncResult() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1UpgradeMessageBody.ReadAsyncInternalAwaited(ValueTask1 readTask, CancellationToken cancellationToken) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.ReadAsyncInternal(Memory1 destination, CancellationToken cancellationToken) at System.Net.WebSockets.ManagedWebSocket.EnsureBufferContainsAsync(Int32 minimumRequiredBytes, CancellationToken cancellationToken, Boolean throwOnPrematureClosure) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory1 payloadBuffer, CancellationToken cancellationToken) at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory1 payloadBuffer, CancellationToken cancellationToken) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Threading.Tasks.ValueTask`1.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state) --- End of stack trace from previous location --- at Microsoft.WebAssembly.Diagnostics.DevToolsProxy.ReadOne(WebSocket socket, CancellationToken token) --- End of inner exception stack trace --- at Microsoft.WebAssembly.Diagnostics.DevToolsProxy.Run(Uri browserUri, WebSocket ideSocket)
This is the VS output screen details:
Exception thrown: 'System.Net.Sockets.SocketException' in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll
Exception thrown: 'System.Net.Sockets.SocketException' in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll
The program '' has exited with code 4294967295 (0xffffffff).
Exception thrown: 'Microsoft.AspNetCore.Connections.ConnectionResetException' in System.Private.CoreLib.dll
Exception thrown: '' in Unknown Module.
The thread 0x1 has exited with code 0 (0x0).
The program 'service-worker.js' has exited with code 4294967295 (0xffffffff).
The program '[25288] Chatter.Server.exe' has exited with code 4294967295 (0xffffffff).
The thread 0x0 has exited with code 0 (0x0).
The program 'localhost:7151' has exited with code 4294967295 (0xffffffff).
Any advise will be greatly appreciated.
Thanx
Riaan
fail: Microsoft.WebAssembly.Diagnostics.DevToolsProxy[0]
DevToolsProxy::Run: Exception System.AggregateException: One or more
errors occurred. (The remote party closed the WebSocket connection
without completing the close handshake.)
To the above error, as far as I know, after update to VS 2022 17.1, it will show the websocket error. And, if check the console output, you will find the above error.
To solve the above error, you can try to use the VS 2022 17.2.0 Preview 2.0 version, this issue has been fixed in this version. Or you can try to install the earlier VS 2022 version, refer this link. I also check it using VS 2022 17.0.4 version, it doesn't have this error, you can try to use this version.
To the Local SQL Server error, I guess you are meeting the following error, right?
To solve the above error, you can use the following migration commands to generate the DataBase first (Or you can use the existing database), then the above error will disappear when you run the application.
add-migration generateDatabase
Update-Database
More detail information about migration, see Migrations Overview.

System.IO.IOException: 'The cloud file provider is not running

.svc (wcf) project don't start on Local IIS
the project was running normally.
but when he bought a new computer, it stopped working.
It may be because iis settings have changed. How can I fix
Error Image
System.IO.IOException
HResult=0x8007016A
Message=The cloud file provider is not running.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.ReadCore(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.FileStream.Read(Byte[] array, Int32 offset, Int32 count)
at System.IO.StreamReader.ReadBuffer()
at System.IO.StreamReader.get_EndOfStream()
at Microsoft.Tools.TestClient.ApplicationSettings.ReadSettingFile()
at Microsoft.Tools.TestClient.ApplicationSettings..ctor()
at Microsoft.Tools.TestClient.ApplicationSettings.GetInstance()
at Microsoft.Tools.TestClient.UI.MainForm.ConstructRecentServiceMenuItems()
at Microsoft.Tools.TestClient.UI.MainForm..ctor()
at Microsoft.Tools.TestClient.UI.MainForm..ctor(String[] endpoints)
at Microsoft.Tools.TestClient.Program.Main(String[] args)
This exception was originally thrown at this call stack:
[External Code]
I think there was a connectivity problem with OneDrive. The problem was solved after restarting the computer

Need help understanding Microsoft Service Trace Viewer log

I'm using Microsoft Service Trace Viewer to check a log for an exception. Exception is:
An error occurred while receiving the HTTP response to ...someservice.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.
The webservice is up and running, and I can reach it fine. I'm generating several reports using methods from the same webservice, and all is fine except one. (this report has a lot of data). I'm guessing it has to do with returning too much data / timeout, but how can I examine this using Microsoft Service Trace Viewer? (I'm new at this tool).
This is my exception string:
<ExceptionString>System.ServiceModel.CommunicationException: An error occurred
while receiving the HTTP response to http://someservice.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.Net.WebException: The underlying connection was closed: An unexpected
error occurred on a receive. --->
System.IO.IOException: Unable to read data from the transport connection: An
existing connection was forcibly closed by the remote host. --->
System.Net.Sockets.SocketException: An existing connection was forcibly
closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---</ExceptionString>
Please help, I really got no clue here...
To try to get a more specific error, enable tracing on both the client and the service, see the links below for more information. Once you have a .svclog file, open it with the trace viewer and click on any activities highlighted in red to view details - if you're exceeding a WCF limit such as MaxReceivedMessageSize it should appear in the log for either the client or service.
http://msdn.microsoft.com/en-us/library/ms733025.aspx
How to turn on WCF tracing?
A common cause for this from what I've encountered is a DataContractSerializer exception. Usually it's a circular reference for me.
Typically what I will do is leave a commented block of code in the service somewhere that uses DataContractSerializer to manually serialize the object that is about to return. You will get a more useful message from the exception it generates.
Assuming you have a "value" variable, here is one way to accomplish the task:
var xs = new DataContractSerializer(value.GetType());
var ms = new MemoryStream();
xs.WriteObject(ms, value);
Then I will execute the code to examine the exception.

WCF service running under custom identity resets connection for WSDL's XSD includes

I have requirements to configure IIS 6 to host a WCF service targeting .NET Framework 4.0 using a custom identity for the worker process. The identity is a highly restricted domain account that is used to identify and manage the permissions for an entire ecosystem of services that interact in the same business process.
I have run aspnet_regiis.exe with the -ga flag to grant this identity permissions to the relevant ASP.NET locations on the server environment and add it to the IIS_WPG group. For the most part, things seem to work relatively well... except for the auto-generated WSDL specification's includes. Accessing the top-level WSDL spec works fine (i.e. path.to/MyService.svc?wsdl), but IIS 6 is resetting the connection before returning the response for the WSDL's includes (i.e. path.to/MyService.svc?xsd=xsd0, etc). This happens both when accessed via loopback on the server and through the public IP. It does not happen when reconfiguring the app pool to run under the default Network Service account.
I haven't found any documentation for this particular problem, but it's not the first time I've had difficulty with certain bits of the .NET Framework not quite working correctly when the IIS 6 worker process is running under a custom domain identity. I haven't configured any special privileges in the Local Security Policy for this account, other than the pre-configured permission for members of IIS_WPG to log on as a batch job. What might I be missing to get the worker functioning correctly?
EDIT:
The Event Viewer contains no errors and IIS logs show the server responding with 200 OK to the request, but the full status value is 200 0 64, indicating a Win32 status code of 64.
The dump I receive on that error from net helpmsg 64 is as follows:
The specified network name is no longer available.
Responses from various entities are below:
Chrome: Error 101 (net::ERR_CONNECTION_RESET): The connection was reset
Firefox: The connection to the server was reset while the page was loading
Eclipse/Java: java.net.SocketException: Connection reset
EDIT:
Service logging (provided by BNL) produced the following exception dump:
System.InvalidOperationException: Unable to generate a temporary class
(result=1). error CS2001: Source file 'C:\WINDOWS\TEMP\vxmgwmnl.0.cs'
could not be found. error CS2008: No inputs specified.
at System.Xml.Serialization.Compiler.Compile(Assembly parent, String
ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
at
System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[]
xmlMappings, Type[] types, String defaultNamespace, Evidence evidence,
XmlSerializerCompilerParameters parameters, Assembly assembly,
Hashtable assemblies) at
System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings,
Type[] types, String defaultNamespace, String location, Evidence
evidence) at System.Xml.Serialization.XmlSerializer..ctor(Type type,
String defaultNamespace) at
System.Xml.Schema.XmlSchema.Write(XmlWriter writer,
XmlNamespaceManager namespaceManager) at
System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.XmlSchemaMessage.OnWriteBodyContents(XmlDictionaryWriter
writer) at
System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter
writer) at
System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message
message, BufferManager bufferManager, Int32 initialOffset, Int32
maxSizeQuota) at
System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message
message, Int32 maxMessageSize, BufferManager bufferManager, Int32
messageOffset) at
System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message
message) at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan
timeout) at
System.ServiceModel.Channels.HttpRequestContext.OnReply(Message
message, TimeSpan timeout) at
System.ServiceModel.Channels.RequestContextBase.Reply(Message message,
TimeSpan timeout) at
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.Reply(MessageRpc&
rpc)
Using the guidelines on the Microsoft KB article Error message when ASP.NET 2.0 is configured to run with a user account: "Unable to generate a temporary class", I located the C:\Windows\Temp directory and inspected its folder properties by right-clicking and choosing Properties. I then navigated to the Security tab and clicked Advanced, then Add. I entered the name of the IIS_WPG group on the local computer and allowed it only the special permission List Folder / Read Data. This has now resolved the issue.

WCF service fails on Windows Server 2003/IIS6 - The underlying connection was closed

I'm experiencing an issue with a WCF service. It is running WebHTTP binding and is a service that receives images.
The problem is that with some images the server fails to receive the incoming stream. The problem is not about size. It can receive files at 100Kb and 4 MB, but fail at files at 800kb. A "defect" image will never succeed, and "good" images will always succeed.
My current suspect is the IIS 6. We have it running in both test and production in house on IIS 7 and IIS 7.5, but at this customer site with IIS 6 it fails.
I can't figure out how to get more debugging info out of IIS 6 to come closer to why it is cutting of the connection.
Below is the nasty details, as I see relevant.
I hope somebody has been here before, and are able to assist me forward.
The Machine
Windows 2003 R2, SP2 + IIS 6, + .Net 2.0 + 3.5
WCF
I have changed the Transfermode to Buffered for my WCF service, and after I did that, the service code don't even get invoked. So I don't suspect WCF settings.
I have enabled meesageLogging for WCF, which again give me almost nothing.
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="-1"/>
</diagnostics>
Logging at the log file afterwards gives me the following:
Basic Information:
Activity Name: Processing message 1.
Time: 2012-03-22 09:27:56.1996
Level: Error
Source: System.ServiceModel
Process: w3wp
Thread: 12
Exception Message:
The number of bytes available is inconsistent with the HTTP Content-Length header. There may have been a network error or the client may be sending invalid requests.
Exception Stakctrace:
System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(Stream
inputStream)
System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception&
requestException)
System.ServiceModel.Channels.HttpRequestContext.CreateMessage()
System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext
context, ItemDequeuedCallback callback)
System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult
result)
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object
state)
System.ServiceModel.PartialTrustHelpers.PartialTrustInvoke(ContextCallback
callback, Object state)
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequestWithFlow(Object
state)
System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke2()
System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke()
System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ProcessCallbacks()
System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.CompletionCallback(Object
state)
System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ScheduledOverlapped.IOCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32
error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
Again, evidence that it is not our WCF service that is responsible for the error, but somewhere in the WCF pipeline.
HTTPERR
I have checked the HTTPERR logs of the IIS, and nothing there but Timer_ConnectionIdle entries, which should be irrelevant.
Fiddler
Fiddler just states the obvious:
[Fiddler] ReadResponse() failed: The server did not return a response for this request.
If there is any need for more information let me know, and I will submit it.
Best regards
/Anders
So I was having this issue too. At first I thought it might be a threading issue (though it was against my better judgement). I made my service calls thread safe and then got down to the real exception after I got past the worker process crashing. The issue for me turned out to be that I was writing to and reading from a share with a given credential using impersonation. However, the share wasn't able to get anymore connections. Even though I was logging out (closing the handle) apparently the connections were still hanging around. What I ended up doing was using a MemoryCache to keep tokens around a little longer and reuse them when the share and user were the same for any given piece of media in my database.
I'm not sure if yours is the same issue but we were def having the same symptoms. My WCF service is reading and writing to a share. Using a SafeThread class (I modified code from here original source: http://www.codeproject.com/KB/threads/SafeThread.aspx) I was able to keep the worker process from crashing and see my real error get logged.
Knowledge base article.
http://support.microsoft.com/kb/179483
Hope this helps someone.