WCF 客户端 - 仅从 WCF 服务返回的流的前 255 个字节包含值
我的任务是管理一个 ASP.Net WebForms 应用程序,该应用程序与 Windows 服务托管的 WCF 服务进行通信。用于服务的绑定是netTcpBinding。
该服务公开上传和下载“文件”的方法。用户选择上传文件,并且 HttpPostFile.InputSteam 作为服务“Upload”方法中的参数直接传递给服务。该服务将流作为字节数组保存到数据库[数据库字段数据类型为varbinary (max)]。
文件下载数据流实质上是相反的过程。从数据库中检索字节;加载到WCF服务中的MemoryStream中;然后返回到Web应用程序。
我在上述操作的每个步骤(在客户端(Web 应用程序)和服务上)捕获了流(发送/接收)中包含的数据。我已循环遍历每个流中包含的字节并将其写入平面文件。
每种情况下的字节数组都是相同的[字节值;和流中的字节数],文件下载操作除外。流从 WCF 服务返回到 Web 应用程序的位置。这里接收到的字节数是正确的,但仅填充了前 255 个字节。剩余字节的值为零
我对绑定值进行了一系列实验性更改 - 在服务的客户端中 - 因为我相信问题一定出在这里。到目前为止,我还没有以任何方式影响返回的字节的状态。客户端和服务的日志没有显示任何抛出异常或任何其他问题。
我在为客户端和服务器应用程序设置正确的绑定(和其他配置)属性组合方面没有太多经验 - 过去一直依赖默认值。我们需要将服务和客户端配置为传输最大允许的文件大小。不幸的是我不能使用 MTOM。
这篇文章和链接,没有为我提供任何内容洞察力。到目前为止,我还没有找到其他有帮助的信息。
希望有人可以帮助我解决可能出现的问题。以下是我正在使用的绑定:
客户端 [web.config]:
<bindings>
<netTcpBinding>
<binding name="TCP"
closeTimeout="00:01:00"
openTimeout="00:10:00"
receiveTimeout="00:01:00" sendTimeout="00:01:00"
transferMode="Streamed"
maxBufferPoolSize="512"
maxBufferSize="2147483647"
maxConnections="10"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="4096"
maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
服务:
<netTcpBinding>
<binding name="netTCP"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:01:00" sendTimeout="00:01:00"
transferMode="Streamed"
listenBacklog="30"
maxBufferPoolSize="512"
maxBufferSize="2147483647"
maxConnections="30"
maxReceivedMessageSize="2147483647"
portSharingEnabled="true">
<readerQuotas maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="4096"
maxNameTableCharCount="2147483647" />
</binding>
</netTcpBinding>
I have been tasked to look after an ASP.Net WebForms application that communicates with a WCF service hosted by a Windows service. The binding used for the service is netTcpBinding.
The service exposes methods to Upload and Download ‘files’. The user select to upload a file and the HttpPostFile.InputSteam is passed directly to the service as a parameter in the service 'Upload' method. The service saves the stream as a byte array to the database [database field data type is varbinary (max)].
The file download data flow is essentially the reverse process. The bytes are retrieved from the database; loaded into a MemoryStream in the WCF service; and then returned to the Web Application.
I have captured the data contained in the streams (sent / received) at each step in the above operations - on the client (web app) and the service. I have looped through and written out to a flat file the bytes contained in each stream.
The byte array in each case is identical [byte value; and number of bytes in the stream] except for the File Download operation. At the point where the stream is returned to the Web Application from the WCF service. Here the number of bytes received is correct but only the first 255 bytes are populated. The values of the remaining bytes are zero
I have made a host of experimental changes to the binding values - in both the client at service - as I believe that the problem must lie here. To date I have not influenced the status of the bytes returned in any way. The logs for the Client and service do not show any that any exceptions are thrown or any other problems.
I do not have much experience in setting the correct combinations of binding (and other configuration) attributes for Client and Server applications – having relied on defaults in the past. We need the service and client to be configured to transfer the maximum allowable file size. Unfortunately I cannot use MTOM.
This post and links, did not offer me any insight. So far I have found no other information that helps.
Hopefully someone can assist me with what the issue might be. Below are the bindings that I am using:
Client [web.config]:
<bindings>
<netTcpBinding>
<binding name="TCP"
closeTimeout="00:01:00"
openTimeout="00:10:00"
receiveTimeout="00:01:00" sendTimeout="00:01:00"
transferMode="Streamed"
maxBufferPoolSize="512"
maxBufferSize="2147483647"
maxConnections="10"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="4096"
maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
Service:
<netTcpBinding>
<binding name="netTCP"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:01:00" sendTimeout="00:01:00"
transferMode="Streamed"
listenBacklog="30"
maxBufferPoolSize="512"
maxBufferSize="2147483647"
maxConnections="30"
maxReceivedMessageSize="2147483647"
portSharingEnabled="true">
<readerQuotas maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="4096"
maxNameTableCharCount="2147483647" />
</binding>
</netTcpBinding>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
愚蠢的我。我想我已经明白了。
绑定没问题。我没有处理从流中正确读取字节到客户端缓冲区的问题。
Silly me. I think I have got it.
The bindings were OK. I was not dealing with reading the bytes correctly from the stream into the buffer on the client.