开发者

WCF Client - only first 255 bytes of stream returned from WCF service contain values

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开发者_如何学Go 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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜