What does it mean that the CopyTo method hangs forever? Has it encountered an exception? I tested and found no problems. Here is my demo:
[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
public interface ICalculator
{
[OperationContract]
Stream RequestEncrypt();
}
public class Calcuator : ICalculator
{
public Stream RequestEncrypt()
{
string str = "i am a string";
byte[] array = Encoding.ASCII.GetBytes(str);
MemoryStream stream = new MemoryStream(array);
StreamReader reader = new StreamReader(stream);
return stream;
}
}
class Program
{
static void Main(string[] args)
{
// Step 1: Create a URI to serve as the base address.
Uri baseAddress = new Uri("net.tcp://localhost:8000/GettingStarted/");
// Step 2: Create a ServiceHost instance.
ServiceHost selfHost = new ServiceHost(typeof(Calcuator), baseAddress);
try
{
NetTcpBinding netTcpBinding = new NetTcpBinding(SecurityMode.None) { TransferMode = TransferMode.Streamed };
// Step 3: Add a service endpoint.
selfHost.AddServiceEndpoint(typeof(ICalculator), netTcpBinding, "CalculatorService");
// Step 4: Enable metadata exchange.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
// smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
Binding mexbinding = MetadataExchangeBindings.CreateMexTcpBinding();
selfHost.AddServiceEndpoint(typeof(IMetadataExchange), mexbinding, "mex");
// Step 5: Start the service.
selfHost.Open();
Console.WriteLine("The service is ready.");
// Close the ServiceHost to stop the service.
Console.WriteLine("Press <Enter> to terminate the service.");
Console.WriteLine();
Console.ReadLine();
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occurred: {0}", ce.Message);
selfHost.Abort();
}
}
}
This is WCF Service.
In UWP, I successfully obtained the Stream and converted it into a string.
UPDATE:
You can try to increase the message size quotas:
<bindings>
<NetTcpBinding>
<binding name="NetTcpBinding"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000"/>
</binding>
</NetTcpBinding>
</bindings>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…