将流上载到WCF时出现问题 [英] Problems when uploading a stream to WCF

查看:114
本文介绍了将流上载到WCF时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将流上传到自托管(Windows服务)WCF服务。

.Net 4.5在客户端和服务器上。

使用的协议是net.tcp,客户端使用ChannelFactory而不是代理(更容易开发imo)。

有一个防火墙保护客户端,所有传入端口都关闭(允许启动通信的唯一一方是客户端)所以来自服务器的所有数据包都必须是NAT 'ed(现在至少起作用了)。
$


服务器没有指定任何东西,因此使用默认的AutoDisposeParameters(true)而没有OperationCompleted来处理流服务器端。

服务器实现了一个SaveStream方法,该方法将uploadedStream作为参数(实际上是一个包含此流和一些元数据的对象,但我认为这无关紧要),

打开本地文件流并执行uploadStream.CopyTo(localFileStream)应用于上传的流,然后在返回之前关闭本地文件流。 br />


客户端打开一个fileStream,使用fileStream作为参数调用服务器SaveStream方法(如上所述,实际上也作为携带一些元数据的对象的一部分)并最终关闭fileStream。



这个工作正常工作几个月,客户来电约。每隔10秒,但几天前它突然停止工作,服务器记录异常消息大致如下:

(服务器正在运行它的OS文化信息,这不是英语,所以我的翻译可能不是确切,下一个版本将强制en-US文化信息)
$
" b $ b $ System.IO.IOException:读取流时发生异常。 ---> System.Xml.XmlException:期望来自命名空间http://tempuri.org/的startelement FileData。从命名空间http://tempuri.org/找到元素FileData。

    at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader,String res,String arg1,String arg2,String arg3)

    at System.Xml.XmlDictionaryReader.MoveToStartElement(String localName,String namespaceUri)

    at System.Xml.XmlBaseReader.ReadStartElement(String localName,String namespaceUri)

    at System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream.Read(Byte [] buffer,Int32 offset,Int32 count)

    ---内部异常堆栈跟踪结束---

    at System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream.Read(Byte [] buffer,Int32 offset,Int32 count)

    at System.IO.Stream.InternalCopyTo(Stream destination,Int32 bufferSize)

    at<服务器位置信息源码>

"
$


异常发生在上面提到的CopyTo方法或下一个关闭本地fileStream的行(这是在堆栈跟踪中指向的亚麻,但应该与此无关)。
$


似乎有在几天前问题开始后100%一致地发生,每10秒记录一次问题。


服务器,特别是客户端部分无法进行调试,我不知道即使有空,也要知道从哪里开始。

我无法在本地重现问题。



堆栈跟踪指的是startelement FileData,它是保存元数据和流的对象的类名。



涉及的网络本地和网络质量似乎都很好,因为使用net.tcp我无法相信消息被"剃光" ;因为堆栈跟踪可能意味着我很困惑发生了什么以及为什么。

解决方案

你有一个堆栈跟踪,但没有inner.exception.message ?

Uploading stream to self hosted (windows service) WCF service.
.Net 4.5 on both client and server.
Protocol used is net.tcp and client uses ChannelFactory instead of proxy (much easier development i.m.o.).
There is a firewall protecting the client with all incoming ports closed (the only party allowed to initiate communication is the client) so all packets from server must be NAT'ed (this has been working at least uptil now).

Server does not specify anything and thus uses default AutoDisposeParameters (true) and no OperationCompleted to dispose the stream on the server-side.
Server implements a SaveStream method which takes the uploadedStream as parameter (actually an object holding this stream and some metadata, but that shouldn't matter I guess),
opens a local filestream and performs uploadedStream.CopyTo(localFileStream) applied on the uploaded stream and then closes the local filestream before returning.

Client opens a fileStream, calls the servers SaveStream method with the fileStream as parameter (as above, actually as part of an object carrying some metadata as well) and finally closes the fileStream.

This has been working fine for a couple of months with a call from the client approx. every 10 seconds, but a few days ago it suddenly stopped working and the server logged exception messages approx as follows:
(Server is running with it's OS culture info which is not english so my translation is perhaps not exact, next release will force en-US culture info)
"
System.IO.IOException: An exception occurred when reading the stream. ---> System.Xml.XmlException: Expected the startelement FileData from namespace http://tempuri.org/. Found the element FileData from namespace http://tempuri.org/.
   at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
   at System.Xml.XmlDictionaryReader.MoveToStartElement(String localName, String namespaceUri)
   at System.Xml.XmlBaseReader.ReadStartElement(String localName, String namespaceUri)
   at System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   --- End of internal exception stacktrace ---
   at System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.Stream.InternalCopyTo(Stream destination, Int32 bufferSize)
   at <location info of servers sourcecode>
"

The exception happens at the CopyTo method mentioned above or possibly the next line where the local fileStream is closed (this is the linenumber which was pointed at in the stacktrace, but should have nothing to do with this).

It seems to have happened 100% consistently after the problem started a few days ago, problem logged every 10 seconds

The server, and particularly the client is partly unavailable for debugging and I don't even have a clue of where to start even if available.
I have not been able to repro the problem locally.

The stacktrace refers to the startelement FileData which is the class name of the object holding metadata and the stream.

The networks involved are both local and network quality seems to be good and since net.tcp is used I cannot believe that messages are "shaved" as the stacktrace could imply and I am very confused what is happening and why.

解决方案

You have a stack trace, but no inner.exception.message?


这篇关于将流上载到WCF时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆