简体   繁体   English

在WCF服务中从流获取字节数组的问题

[英]Problem with getting byte array from stream in WCF Service

EDIT: Sorry Here was something tottaly wrong. 编辑:对不起,这完全是错误的。

EDIT: again from the beginning: 编辑:再次从头开始:

I have a WCF Service and at some point of my program I am getting a pointer to a byte array. 我有一个WCF服务,并且在程序的某个时刻,我得到了一个指向字节数组的指针。 I want to copy bytes from this byte array / pointer to another byte array and send it to client. 我想将字节从此字节数组/指针复制到另一个字节数组,并将其发送给客户端。 I also have a test program (not WCF Service) that is running the same code: 我也有一个运行相同代码的测试程序(不是WCF服务):

            uint read = 1;
            uint size = (uint)job.OutputFileParameters[1].ActualSize + 1;
            byte[] arrbyt = new byte[job.OutputFileParameters[1].ActualSize + 1];
            unsafe
            {

                fixed (byte* buffer = arrbyt)
                {
                    int ind = 0;
                    while (read != 0)
                    {
                        str.RemoteRead(out *buffer, size, out read);

                    }

                }
            }

But in test program arrbyt is filled with bytes and everything is ok, but in WCF Service arrbyt is empty. 但是在测试程序中,arrbyt充满了字节,一切正常,但是在WCF服务中,arrbyt为空。 This is my problem sorry for previous version i was tired ;) 这是我的问题,对于以前的版本,我很累;)

The problem was that the same code has different result in WCF Service and in normal windows app. 问题在于,相同的代码在WCF服务和常规Windows应用程序中具有不同的结果。 In WCF Service when RemoteRead reads 0 bytes it puts zeros to arrbyt, in Windows app after reading 0 bytes arrbyte stays as it was without any changes with proper values inside. 在WCF服务中,当RemoteRead读取0字节时,它将arrbyt零。在Windows应用中,读取0字节后arrbyte保持原样,并且内部没有任何适当的值更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM