public static void Main(string[] args) { // improve http performance ServicePointManager.DefaultConnectionLimit = 1000; ServicePointManager.Expect100Continue = false; ServicePointManager.UseNagleAlgorithm = false; SessionStartInfo info = new SessionStartInfo(headnode, serviceName); info.Username = "******"; info.Password = "******"; info.TransportScheme = TransportScheme.Http; info.UseAzureQueue = false; info.Secure = false; Console.Write("Creating a session for SoamInvokeService..."); List<BrokerClient<ISoamSvc>> clientList = new List<BrokerClient<ISoamSvc>>(); // Create a durable session // Request and response messages in a durable session are persisted so that // in event of failure, no requests nor responses will be lost. Another authorized // client can attached to a session with the same session Id and retrieve responses using (Session session = Session.CreateSession(info)) { Console.WriteLine("done session id = {0}", session.Id); //NetTcpBinding binding = new NetTcpBinding(SecurityMode.Transport); Console.WriteLine("Sending {0} requests...", numRequests); DateTime timeMark1 = DateTime.Now; SendRequests(session, clientList); DateTime timeMark2 = DateTime.Now; double elapsedTimeSec = (timeMark2 - timeMark1).TotalMilliseconds / 1000.0; Console.WriteLine("Done sending {0} requests ... throughput={1}", numRequests, numRequests / elapsedTimeSec); Console.WriteLine("Retrieving responses..."); GetResponses(clientList); DateTime timeMark3 = DateTime.Now; elapsedTimeSec = (timeMark3 - timeMark2).TotalMilliseconds / 1000.0; Console.WriteLine("Done retrieving {0} responses ... throughput={1}", numRequests, numRequests / elapsedTimeSec); elapsedTimeSec = (timeMark3 - timeMark1).TotalMilliseconds / 1000.0; Console.WriteLine("Total throughput={0}", numRequests / elapsedTimeSec); //explict close the session to free the resource session.Close(); } Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
static void Main(string[] args) { //change the headnode name here const string headnode = "localhost"; const string serviceName = "JavaEchoSvc1"; const int numRequests = 12; SessionStartInfo info = new SessionStartInfo(headnode, serviceName); Console.Write("Creating a session for EchoService..."); // Create a durable session // Request and response messages in a durable session are persisted so that // in event of failure, no requests nor responses will be lost. Another authorized // client can attached to a session with the same session Id and retrieve responses using (DurableSession session = DurableSession.CreateSession(info)) { Console.WriteLine("done session id = {0}", session.Id); NetTcpBinding binding = new NetTcpBinding(SecurityMode.Transport); // Create a BrokerClient proxy // This proxy is able to map One-Way, Duplex message exchange patterns // with the Request / Reply Services. As such, the client program can send the // requests, exit and re-attach to the session to retrieve responses (see the // FireNRecollect project for details using (BrokerClient<IEchoSvc> client = new BrokerClient<IEchoSvc>(session, binding)) { Console.Write("Sending {0} requests...", numRequests); for (int i = 0; i < numRequests; i++) { // EchoRequest are created as you add Service Reference // EchoService to the project EchoRequest request = new EchoRequest("hello world!"); client.SendRequest<EchoRequest>(request, i); } // Flush the message. After this call, the runtime system // starts processing the request messages. If this call is not called, // the system will not process the requests. The client.GetResponses() will return // with an empty collection client.EndRequests(); Console.WriteLine("done"); Console.WriteLine("Retrieving responses..."); // GetResponses from the runtime system // EchoResponse class is created as you add Service Reference "EchoService" // to the project foreach (var response in client.GetResponses<EchoResponse>()) { try { string reply = response.Result.EchoResult; Console.WriteLine("\tReceived response for request {0}: {1}", response.GetUserData<int>(), reply); } catch (Exception ex) { Console.WriteLine("Error occured while processing {0}-th request: {1}", response.GetUserData<int>(), ex.Message); } } Console.WriteLine("Done retrieving {0} responses", numRequests); } //explict close the session to free the resource session.Close(); } Console.WriteLine("Press any key to exit."); Console.ReadKey(); }