IHubProxy から別のクライアントにバイト ストリームを転送したいと考えています。バイトストリームを文字列として転送しています。小さな文字も問題なく転送できました。しかし、大きな文字列 (バイトストリームと文字列に変換された画像) を転送しているとき、文字列を転送できません。大きな文字列を転送するにはどうすればよいですか?
string username = Console.ReadLine();
var connection = new HubConnection("http://localhost:51428/");
IHubProxy myHub = connection.CreateHubProxy("ScannerHub"); //This should be same as Hub Name
//Establishing the connection
connection.Start().ContinueWith(task =>
{
if (task.IsFaulted)
{
Console.WriteLine("Failed to start: {0}", task.Exception.GetBaseException());
}
else
{
Console.WriteLine("Success! Connected with client connection id {0}", connection.ConnectionId);
//After connection is established. Register the printer client with client information
myHub.Invoke("RegisterClient", username, connection.ConnectionId, "Printer").ContinueWith(task2 =>
{
if (task2.IsFaulted)
{
Console.WriteLine("An error occurred during the method call {0}", task2.Exception.GetBaseException());
}
else
{
Console.WriteLine("Successfully Registred");
}
});
//In the client (here it is Printer Client) there is a method named getScanRequest
//This method retrieves the scan request and processes it accordingly.
//What is done here is that, in the HubProxy we listen to the calls on current clients
//getScanRequest been hit. If hit. Execute that method.
//Use a Func when you want to return a value
//http://stackoverflow.com/questions/4317479/func-vs-action-vs-predicate
//Func<string, byte[]> scanFunction;
//scanFunction = Scan;
//Action<string> printFunction;
//printFunction = Scan;
//myHub.On("getScanRequest", data => Console.WriteLine("Got Print Request " + data));
//Register on a server side method with a callback function
//myHub.On("getScanRequest", printFunction);
//myHub.On("getScanRequest", data => Console.WriteLine("got print request from "+data));
myHub.On<string>("getScanRequest", (clientUrl) =>
{
string scanByteStream = Scan(clientUrl);
try
{
myHub.Invoke("GetValueFromScanner", scanByteStream);
}
catch (Exception ex)
{
var j = 0;
}
});
}