Ниже структуры сериализуется, и когда сервер (запускает веб-службу WCF) возвращает объект этого, тогда клиент может правильно получать данные.Передача «потока» клиенту вызывает ошибку
[Serializable]
public struct TestInfo
{
public string TestStr;
public int TestInt;
}
Сценарий: Сервер пытается открыть конечную точку и отправить его клиенту, так что клиент будет писать в него файл. Я попытался добавить «Стрим» в структуре, как показано ниже, но это вызывает ошибку.
[Serializable]
public struct TestInfo
{
public string TestStr;
public int TestInt;
public Stream TestStream;
}
Ошибка:
An error occurred while receiving the HTTP response.
This could be due to the service endpoint binding not using the HTTP protocol.
This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down).
System.Net.WebException: The underlying connection was closed:
An unexpected error occurred on a receive. --->
System.IO.IOException: Unable to read data from the transport connection:
An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.TlsStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---
Любая идея, если я что-нибудь не хватает? «Поток» сериализуем, и я подумал, что будет нормально отправлять Stream. Если «Стрим» не лучший способ, то каким-либо другим способом, который я могу попробовать?
Я понятия не имею, почему поток помечается сериализации, но по существу ни один из его фактической реализации не может быть осмысленно сериализованная. Невозможно сериализовать что-то вроде локального доступа к файлам ('FileStream') или локального сетевого соединения (' NetworkStream'/'SslStream') таким образом, который полезен вне локального поля. –