我们在Windows Server 2003上部署了一个WCF服务来处理文件传输。当文件是Unix格式时,我使用System.Diagnostics.Process(.WaitForExit())在初始化阶段将其转换为Dos格式。客户端调用该服务:
obj_DataSenderService = New DataSendClient()
obj_DataSenderService.InnerChannel.OperationTimeout = New TimeSpan(0, System.Configuration.ConfigurationManager.AppSettings("DatasenderServiceOperationTimeout"), 0)
str_DataSenderGUID = obj_DataSenderService.Initialize(xe_InitDetails.GetXMLNode)
这样可以正常工作,但是对于大文件,转换需要10分钟以上,而且我会遇到异常:
类型的第一次机会异常 'System.ServiceModel.CommunicationException' 发生在mscorlib.dll
附加信息:套接字 连接中止。这可能是 由处理你的错误引起的 消息或接收超时 超出远程主机,或 底层网络资源问题。 本地套接字超时是 '00:59:59.8749992'
我尝试配置两个客户端:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IDataSend" closeTimeout="01:00:00"
openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:4000/DataSenderEndPoint"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IDataSend"
contract="IDataSend" name="NetTcpBinding_IDataSend">
<identity>
<servicePrincipalName value="host/localhost" />
<!--<servicePrincipalName value="host/axopwrapp01.Corp.Acxiom.net" />-->
</identity>
</endpoint>
</client>
</system.serviceModel>
服务:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IDataSend" closeTimeout="01:00:00"
openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
maxReceivedMessageSize="65536">
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
但没有运气。在服务跟踪查看器中,我可以看到:
关闭进程超时,等待服务调度完成。
堆栈跟踪:
System.ServiceModel.ServiceChannelManager.CloseInput(时间跨度 超时) System.ServiceModel.Dispatcher.InstanceContextManager.CloseInput(时间跨度 超时) System.ServiceModel.ServiceHostBase.OnClose(时间跨度 超时) System.ServiceModel.Channels.CommunicationObject.Close(时间跨度 超时) System.ServiceModel.Channels.CommunicationObject.Close() DataSenderService.DataSender.OnStop() System.ServiceProcess.ServiceBase.DeferredStop() System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr的 md,Object [] args,对象服务器, Int32 methodPtr,Boolean fExecuteInContext,Object []&amp; outArgs) System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md,Object [] args,对象服务器, Int32 methodPtr,Boolean fExecuteInContext,Object []&amp; outArgs) System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(即时聊天 msg,IMessageSink replySink) System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.DoAsyncCall() System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(对象 O) System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(对象 州) System.Threading.ExecutionContext.runTryCode(对象 用户数据) System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode 代码,CleanupCode backoutCode,Object 用户数据) System.Threading.ExecutionContext.RunInternal(执行上下文 executionContext,ContextCallback 回调,对象状态) System.Threading.ExecutionContext.Run(执行上下文 executionContext,ContextCallback 回调,对象状态) System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack) System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(对象 状态)
非常感谢 鲍尔泰克
答案 0 :(得分:0)
您的WCF服务是否实际返回文件内容?如果是这样,也许您应该使用WCF的流功能,并在流式传输时将行结尾从Unix更改为DOS样式,而不是处理文件然后按照您当前的操作返回。读入每一行,然后使用正确的行结束流出。