static void Main(string[] args) { string hostName = "sfv2.eastus.cloudapp.azure.com"; Regex ipRex = new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"); IServicePartitionResolver partitionResolver = new ServicePartitionResolver(hostName + ":19000"); var binding = WcfUtility.CreateTcpClientBinding(); var resolveResults = partitionResolver.ResolveAsync(new Uri("fabric:/CalculatorApplication/CalculatorService"), ServicePartitionKey.Singleton, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), new System.Threading.CancellationToken()).Result; var endpoint = resolveResults.GetEndpoint(); var endpointObject = JsonConvert.DeserializeObject <JObject>(endpoint.Address); var addressString = ((JObject)endpointObject.Property("Endpoints").Value)[""].Value <string>(); addressString = ipRex.Replace(addressString, hostName, 1); var endpointAddress = new EndpointAddress(addressString); var channel = ChannelFactory <ICalculatorService> .CreateChannel(binding, endpointAddress); for (int i = 0; i < 10; i++) { var calculatorServiceCommunicationClient = new WcfCommunicationClient <ICalculatorService>(channel); var result = calculatorServiceCommunicationClient.Channel.Add(2, 3).Result; Console.WriteLine(result); } }
public static TResult Invoke <TResult>(Func <WcfCommunicationClient <T>, TResult> method, string serviceName) { lock (locker) { factory = new WcfCommunicationClientFactory <T>(clientBinding: WcfUtility.CreateTcpClientBinding(), servicePartitionResolver: new ServicePartitionResolver()); proxy = new ServicePartitionClient <WcfCommunicationClient <T> >( communicationClientFactory: factory, serviceUri: ServiceFabricManager.ServiceFabricMapper[serviceName].ServiceFabricUri, listenerName: ServiceFabricManager.ServiceFabricMapper[serviceName].ContractListenerMapper[typeof(T)]); try { var result = proxy.InvokeWithRetry(method); return(result); } catch (TimeoutException e) { Trace.TraceError("WCF Client Timeout Exception " + e.Message); throw; } catch (CommunicationException e) { Trace.TraceError("WCF Client Communication Exception " + e.Message); throw; } catch (Exception e) { Trace.TraceError("WCF Client Exception " + e.Message); throw; } } }
static void Main(string[] args) { Uri serviceUri = new Uri("fabric:/SimpleStoreApplication/ShoppingCartService"); IServicePartitionResolver serviceResolver = ServicePartitionResolver.GetDefault(); Binding binding = WcfUtility.CreateTcpClientBinding(); var wcfClientFactory = new WcfCommunicationClientFactory <IShoppingCartService>( clientBinding: binding, servicePartitionResolver: serviceResolver); for (int i = 1; i <= 3; i++) { // var shoppingClient = new Client(wcfClientFactory, serviceUri, i); var shoppingClient = new Client(wcfClientFactory, serviceUri, "Customer " + i); shoppingClient.AddItem(new ShoppingCartItem { ProductName = "XBOX ONE", UnitPrice = 329.0, Amount = 2 }).Wait(); PrintPartition(shoppingClient); var list = shoppingClient.GetItems().Result; foreach (var item in list) { Console.WriteLine(string.Format("{0}: {1:C2} X {2} = {3:C2}", item.ProductName, item.UnitPrice, item.Amount, item.LineTotal)); } } Console.ReadKey(); }
static void Main(string[] args) { Uri serviceUri = new Uri("fabric:/SimpleStoreApplication/ShoppingCartService"); Binding binding = WcfUtility.CreateTcpClientBinding(); IServicePartitionResolver partitionResolver = new ServicePartitionResolver(() => new FabricClient()); for (int customerId = 0; customerId < 10; customerId++) { Client shoppingClient = new Client( new WcfCommunicationClientFactory <IShoppingCartService>(binding, null, partitionResolver), serviceUri, customerId); shoppingClient.AddItem(new ShoppingCartItem { ProductName = "XBOX ONE", UnitPrice = 329.0, Amount = 2 }).Wait(); PrintPartition(shoppingClient); var list = shoppingClient.GetItems().Result; foreach (var item in list) { Console.WriteLine($"{item.ProductName}: {item.UnitPrice:C2} x {item.Amount} = {item.LineTotal:C2}"); } } Console.ReadKey(); }
static async Task Main(string[] args) { if (args == null || !args.Any()) { Console.WriteLine("Debe especificar el identificador del producto"); return; } var id = args[0]; var serviceUri = new Uri("fabric:/LinkedInLearning/Products"); var binding = WcfUtility.CreateTcpClientBinding(); var servicePartitionResolver = ServicePartitionResolver.GetDefault(); var wcfCommunicationClientFactory = new WcfCommunicationClientFactory <IProductsService>(binding, null, servicePartitionResolver); var servicePartitionClient = new ServicePartitionClient <WcfCommunicationClient <IProductsService> >(wcfCommunicationClientFactory, serviceUri); Console.WriteLine($"Consultando {id} ..."); var result = await servicePartitionClient.InvokeWithRetryAsync(client => client.Channel.GetProductAsync(id)); Console.WriteLine($"{result.Id} {result.Nombre}"); }
private static void CallCloud() { var binding = WcfUtility.CreateTcpClientBinding(); var partitionResolver = new ServicePartitionResolver("ilrprocessingsfpoc.uksouth.cloudapp.azure.com:777", "ilrprocessingsfpoc.uksouth.cloudapp.azure.com:19000"); var wcfClientFactory = new WcfCommunicationClientFactory <IValidationServiceStateful>(binding, servicePartitionResolver: partitionResolver); var serviceUri = new Uri("fabric:/DCT.ILR.Processing.POC/DCT.ILR.VadationServiceStateful"); var client = new ValidationServiceClient(wcfClientFactory, serviceUri, new ServicePartitionKey(LongRandom())); var resolved = partitionResolver.ResolveAsync(new Uri("fabric:/DCT.ILR.Processing.POC/DCT.ILR.VadationServiceStateful"), new ServicePartitionKey(9223372036854775807), CancellationToken.None).Result; do { var correlationId = Guid.NewGuid(); Console.WriteLine(client.Validation(new Models.Models.IlrContext() { CorrelationId = correlationId, ContainerReference = "ilr-files", Filename = "ILR-10006341-1718-20171107-113456-01.xml", //Filename = "ILR-10006148-1718-20170203-144336-03.xml", IsShredAndProcess = false }).Result); Console.ReadKey(); } while (true); }
public async Task <string> ApplyUpdates(Delta delta) { Binding binding = WcfUtility.CreateTcpClientBinding(maxMessageSize: 1024 * 1024 * 1024); ServicePartitionResolver servicePartitionResolver = new ServicePartitionResolver(() => new FabricClient()); WcfCommunicationClientFactory <INetworkModelGDAContract> communicationClientFactory = new WcfCommunicationClientFactory <INetworkModelGDAContract>(binding, servicePartitionResolver: servicePartitionResolver); Uri uri = new Uri("fabric:/LoadFlowApplication/NMSGdaService"); NetworkModelGdaClient networkModelGdaClient = new NetworkModelGdaClient(communicationClientFactory, uri, new ServicePartitionKey(0)); string updateResult = "Apply Updates Report:\r\n"; System.Globalization.CultureInfo culture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); if ((delta != null) && (delta.NumberOfOperations != 0)) { //// NetworkModelService->ApplyUpdates //updateResult = GdaQueryProxy.ApplyUpdate(delta).ToString(); try { updateResult = (await networkModelGdaClient.InvokeWithRetryAsync(client => client.Channel.ApplyUpdate(delta))).ToString(); } catch (Exception e) { string message = e.Message; } } Thread.CurrentThread.CurrentCulture = culture; return(updateResult); }
/// <summary> /// Creates a service remoting client factory that can be used by the /// <see cref="Microsoft.ServiceFabric.Services.Remoting.Client.ServiceProxyFactory"/> /// to create a proxy for the remoted interface of the service. /// </summary> /// <param name="callbackMessageHandler"> /// Client implementation where the callbacks should be dispatched. /// </param> /// <returns> /// A <see cref="Microsoft.ServiceFabric.Services.Remoting.V2.Wcf.Client.WcfServiceRemotingClientFactory"/>. /// </returns> public override V2.Client.IServiceRemotingClientFactory CreateServiceRemotingClientFactoryV2( IServiceRemotingCallbackMessageHandler callbackMessageHandler) { return(new Services.Remoting.V2.Wcf.Client.WcfServiceRemotingClientFactory( WcfUtility.CreateTcpClientBinding( this.GetMaxMessageSize(), this.GetOpenTimeout(), this.GetCloseTimeout()), callbackMessageHandler)); }
/// <summary> /// Creates a service remoting client factory to connect to the remoted actor interfaces. /// </summary> /// <param name="callbackClient"> /// Client implementation where the callbacks should be dispatched. /// </param> /// <returns> /// A <see cref="Microsoft.ServiceFabric.Services.Remoting.Wcf.Client.WcfServiceRemotingClientFactory"/> /// as <see cref="Microsoft.ServiceFabric.Services.Remoting.Client.IServiceRemotingClientFactory"/> /// that can be used with <see cref="Microsoft.ServiceFabric.Actors.Client.ActorProxyFactory"/> to /// generate actor proxy to talk to the actor over remoted actor interface. /// </returns> public override IServiceRemotingClientFactory CreateServiceRemotingClientFactory( IServiceRemotingCallbackClient callbackClient) { return(new WcfActorRemotingClientFactory( WcfUtility.CreateTcpClientBinding( maxMessageSize: this.GetMaxMessageSize(), openTimeout: this.GetOpenTimeout(), closeTimeout: this.GetCloseTimeout()), callbackClient)); }
/// <summary> /// Creates a service remoting client factory to connect to the remoted actor interfaces. /// </summary> /// <param name="callbackClient"> /// Client implementation where the callbacks should be dispatched. /// </param> /// <returns> /// A <see cref="Microsoft.ServiceFabric.Actors.Remoting.V1.Wcf.Client.WcfActorRemotingClientFactory"/> /// as <see cref="Microsoft.ServiceFabric.Services.Remoting.V1.Client.IServiceRemotingClientFactory"/> /// that can be used with <see cref="ActorProxyFactory"/> to /// generate actor proxy to talk to the actor over remoted actor interface. /// </returns> public override Microsoft.ServiceFabric.Services.Remoting.V1.Client.IServiceRemotingClientFactory CreateServiceRemotingClientFactory( Microsoft.ServiceFabric.Services.Remoting.V1.IServiceRemotingCallbackClient callbackClient) { return(new Microsoft.ServiceFabric.Actors.Remoting.V1.Wcf.Client.WcfActorRemotingClientFactory( WcfUtility.CreateTcpClientBinding( maxMessageSize: this.GetMaxMessageSize(), openTimeout: this.GetOpenTimeout(), closeTimeout: this.GetCloseTimeout()), callbackClient)); }
/// <summary> /// Creates a V1 service remoting client factory that can be used by the /// <see cref="Microsoft.ServiceFabric.Services.Remoting.Client.ServiceProxyFactory"/> /// to create a proxy for the remoted interface of the service. /// </summary> /// <param name="callbackClient"> /// Client implementation where the callbacks should be dispatched. /// </param> /// <returns> /// A <see cref="Microsoft.ServiceFabric.Services.Remoting.V1.Wcf.Client.WcfServiceRemotingClientFactory"/>. /// </returns> public override V1.Client.IServiceRemotingClientFactory CreateServiceRemotingClientFactory( V1.IServiceRemotingCallbackClient callbackClient) { return(new V1.Wcf.Client.WcfServiceRemotingClientFactory( WcfUtility.CreateTcpClientBinding( this.GetMaxMessageSize(), this.GetOpenTimeout(), this.GetCloseTimeout()), callbackClient)); }
private WcfClient <IScadaStorageService> BuildClient() { Binding binding = WcfUtility.CreateTcpClientBinding(); IServicePartitionResolver partitionResolver = ServicePartitionResolver.GetDefault(); var wcfClientFactory = new WcfCommunicationClientFactory <IScadaStorageService>(clientBinding: binding, servicePartitionResolver: partitionResolver); var ServiceUri = new Uri(_uri); var client = new WcfClient <IScadaStorageService>(wcfClientFactory, ServiceUri, new Microsoft.ServiceFabric.Services.Client.ServicePartitionKey(1)); return(client); }
private WcfClient <IFEPServiceAsync> BuildClient() { Binding binding = WcfUtility.CreateTcpClientBinding(); IServicePartitionResolver partitionResolver = ServicePartitionResolver.GetDefault(); var wcfClientFactory = new WcfCommunicationClientFactory <IFEPServiceAsync>(clientBinding: binding, servicePartitionResolver: partitionResolver); var ServiceUri = new Uri(_uri); var client = new WcfClient <IFEPServiceAsync>(wcfClientFactory, ServiceUri); return(client); }
static void Main(string[] args) { Uri serviceUri = new Uri("fabric:/CalculatorApplication3/CalculatorService"); IServicePartitionResolver serviceResolver = ServicePartitionResolver.GetDefault(); Binding binding = WcfUtility.CreateTcpClientBinding(); var wcfClientFactory = new WcfCommunicationClientFactory <ICalculatorService>( clientBinding: binding, servicePartitionResolver: serviceResolver); var calcClient = new Client(wcfClientFactory, serviceUri); Console.WriteLine(calcClient.Add(3, 5).Result); Console.ReadKey(); }
private static async Task reportCancellation(string url) { Binding binding = WcfUtility.CreateTcpClientBinding(); IServicePartitionResolver partitionResolver = ServicePartitionResolver.GetDefault(); var wcfClientFactory = new WcfCommunicationClientFactory <IStateAggregator>( clientBinding: binding, servicePartitionResolver: partitionResolver ); var jobClient = new ServicePartitionClient <WcfCommunicationClient <IStateAggregator> >( wcfClientFactory, new Uri("fabric:/AudioTranscriptionApp/StateAggregator")); await jobClient.InvokeWithRetryAsync(client => client.Channel.ReportCancellation(url)); }
public TContract CreateClient <TClient, TContract>(Uri serviceUri, ServicePartitionKey servicePartition) where TContract : class, IService, IHealthChecker where TClient : WcfSeviceFabricClientBase <TContract> { var binding = WcfUtility.CreateTcpClientBinding(); var partitionResolver = ServicePartitionResolver.GetDefault(); var wcfClientFactory = new WcfCommunicationClientFactory <TContract>(clientBinding: binding, servicePartitionResolver: partitionResolver); TContract client = (TContract)Activator.CreateInstance(typeof(TClient), new object[] { wcfClientFactory, serviceUri, servicePartition }); //CheckIsAlive(client, serviceUri); return(client); }
public async Task <IEnumerable <JobStatus> > Jobs() { Binding binding = WcfUtility.CreateTcpClientBinding(); IServicePartitionResolver partitionResolver = ServicePartitionResolver.GetDefault(); var wcfClientFactory = new WcfCommunicationClientFactory <IStateAggregator>( clientBinding: binding, servicePartitionResolver: partitionResolver ); var jobClient = new ServicePartitionClient <WcfCommunicationClient <IStateAggregator> >( wcfClientFactory, new Uri("fabric:/AudioTranscriptionApp/StateAggregator")); var result = await jobClient.InvokeWithRetryAsync(client => client.Channel.ListJobs()); return(result); }
protected string GetTenantDBConnection(string tenant) { Binding binding = WcfUtility.CreateTcpClientBinding(); IServicePartitionResolver partitionResolver = ServicePartitionResolver.GetDefault(); var wcfClientFactory = new WcfCommunicationClientFactory <IDbConnectionService>(clientBinding: binding, servicePartitionResolver: partitionResolver); var client = new ServicePartitionClient <WcfCommunicationClient <IDbConnectionService> >(wcfClientFactory, new Uri(SF_CONFIG_DBCONNECTION_SERVICE)); var results = client.InvokeWithRetry( c => c.Channel.IdentifyTenantDatabase(tenant) ); return(results); }
static void Main(string[] args) { Binding binding = WcfUtility.CreateTcpClientBinding(); IServicePartitionResolver partitionResolver = ServicePartitionResolver.GetDefault(); var wcfClientFactory = new WcfCommunicationClientFactory <ICalculatorService> (clientBinding: null, servicePartitionResolver: partitionResolver); for (int i = 0; i < 10; i++) { var calculatorServiceCommunicationClient = new ServicePartitionClient <WcfCommunicationClient <ICalculatorService> > (wcfClientFactory, new Uri("fabric:/CalculatorApplication/CalculatorService")); var result = calculatorServiceCommunicationClient.InvokeWithRetryAsync(client => client.Channel.Add(2, 3)); Console.WriteLine(result.Result); } // Console.ReadLine(); }
public async Task VisitWcfAsync(ServiceMessage message) { var fabricClient = new FabricClient(FabricClientRole.Admin); var partitionList = await fabricClient.QueryManager.GetPartitionListAsync(new Uri(Service4Uri)); var bindings = WcfUtility.CreateTcpClientBinding(); var partitionResolver = ServicePartitionResolver.GetDefault(); message.StampThree.Visited = true; message.StampThree.TimeNow = DateTime.UtcNow; foreach (var partition in partitionList) { var partitionInfo = (Int64RangePartitionInformation)partition.PartitionInformation; var wcfClientProxy = new WcfCommunicationClientFactory <IServiceFour>(clientBinding: bindings, servicePartitionResolver: partitionResolver); var wcfClient = new SvcFourWcfCommunicationClient(wcfClientProxy, new Uri(Service4Uri), new ServicePartitionKey(partitionInfo.HighKey), listenerName: "WcfTcp"); await wcfClient.InvokeWithRetryAsync(client => client.Channel.VisitWcfAsync(message)); } }
static void CallWcf() { var ServiceUri = new Uri("fabric:/Application3/Stateful1"); // Create binding Binding binding = WcfUtility.CreateTcpClientBinding(); ServicePartitionResolver servicePartitionResolver = new ServicePartitionResolver(() => new FabricClient()); // Create a partition resolver IServicePartitionResolver partitionResolver = ServicePartitionResolver.GetDefault(); // create a WcfCommunicationClientFactory object. var wcfClientFactory = new WcfCommunicationClientFactory <ICalculator> (clientBinding: binding, servicePartitionResolver: servicePartitionResolver); // // Create a client for communicating with the ICalculator service that has been created with the // Singleton partition scheme. // var calculatorServiceCommunicationClient = new WcfCommunicationClient( wcfClientFactory, ServiceUri, new ServicePartitionKey(1)); // // Call the service to perform the operation. // Stopwatch stopwatch = new Stopwatch(); var total = 0.0; for (int i = 0; i < 1000; i++) { stopwatch.Restart(); var result = calculatorServiceCommunicationClient.InvokeWithRetryAsync( client => client.Channel.Add(2, 3)).Result; stopwatch.Stop(); var used = stopwatch.Elapsed.TotalMilliseconds; total += used; Console.WriteLine($"{i + 1} used: {used}ms, avg:{total / (i + 1)}, result:{result}"); } }
public TContract CreateClient <TClient, TContract>(Uri serviceUri, ServiceType serviceType, int partitionKey = 0) where TContract : class, IService where TClient : WcfSeviceFabricClientBase <TContract> { var binding = WcfUtility.CreateTcpClientBinding(); var partitionResolver = ServicePartitionResolver.GetDefault(); var wcfClientFactory = new WcfCommunicationClientFactory <TContract>(clientBinding: binding, servicePartitionResolver: partitionResolver); ServicePartitionKey servicePartition; if (serviceType == ServiceType.STATEFUL_SERVICE) { servicePartition = new ServicePartitionKey(partitionKey); } else { servicePartition = ServicePartitionKey.Singleton; } TContract client = (TContract)Activator.CreateInstance(typeof(TClient), new object[] { wcfClientFactory, serviceUri, servicePartition }); return(client); }
static async Task Main(string[] args) { var serviceUri = new Uri("fabric:/ECommerce/ECommerce.Api.Orders"); var binding = WcfUtility.CreateTcpClientBinding(); var servicePartitionResolver = ServicePartitionResolver.GetDefault(); var wcfCommunicationClientFactory = new WcfCommunicationClientFactory <IOrdersService>(binding, null, servicePartitionResolver); var servicePartitionClient = new ServicePartitionClient <WcfCommunicationClient <IOrdersService> >(wcfCommunicationClientFactory, serviceUri); Console.WriteLine($"Please wait..."); var result = await servicePartitionClient.InvokeWithRetryAsync(client => client.Channel.GetOrdersAsync()); if (result != null && result.Any()) { foreach (var order in result) { Console.WriteLine($"{order.Id} {order.CustomerId} {order.OrderDate} {order.Total}"); } } }
public async Task <IActionResult> Start(string id) { try { var serviceUri = this._context.CodePackageActivationContext.ApplicationName + "/" + ServiceName; var partitionList = await this._client.QueryManager.GetPartitionListAsync(new Uri(serviceUri)); var bindings = WcfUtility.CreateTcpClientBinding(); var partitionResolver = ServicePartitionResolver.GetDefault(); var message = new ServiceMessage(); message.CommChannel = "WcfNetTcp"; message.SessionId = id; message.StampOne.Visited = true; message.StampOne.TimeNow = DateTime.UtcNow; //var storage = await _manager.GetOrAddAsync<IReliableDictionary<string, ServiceMessage>>("storage"); //using (var tx = _manager.CreateTransaction()) //{ // await storage.AddAsync(tx, message.MessageId, message); // await tx.CommitAsync(); //} foreach (var partition in partitionList) { var partitionInfo = (Int64RangePartitionInformation)partition.PartitionInformation; var wcfClientFactory = new WcfCommunicationClientFactory <IServiceTwo>(clientBinding: bindings, servicePartitionResolver: partitionResolver); var wcfClient = new SvcTwoWcfCommunicationClient(wcfClientFactory, new Uri(serviceUri), new ServicePartitionKey(partitionInfo.HighKey), listenerName: "WcfTcp"); await wcfClient.InvokeWithRetryAsync( client => client.Channel.VisitWcfAsync(message)); } return(Ok(new { id = id })); } catch (Exception e) { return(BadRequest(e.Message)); } }
private async Task uploadTranscript(string fileName, string text, string user) { string connectionString = "[Storage Account Connection String]"; CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("transcripts"); CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName + "transcript.txt"); using (var stream = new MemoryStream(Encoding.Default.GetBytes(text), false)) { await blockBlob.UploadFromStreamAsync(stream); } Binding binding = WcfUtility.CreateTcpClientBinding(); IServicePartitionResolver partitionResolver = ServicePartitionResolver.GetDefault(); var wcfClientFactory = new WcfCommunicationClientFactory <IStateAggregator>( clientBinding: binding, servicePartitionResolver: partitionResolver ); var jobClient = new ServicePartitionClient <WcfCommunicationClient <IStateAggregator> >( wcfClientFactory, new Uri("fabric:/AudioTranscriptionApp/StateAggregator")); await jobClient.InvokeWithRetryAsync(client => client.Channel.ReportCompletion(fileName, blockBlob.Uri.AbsoluteUri, user)); }
public void ConnectToWcfService() { // var ret = HelloProxy.Instance.Hello(); string uri = "net.tcp://localhost:1000/Gateway/WcfService"; var ret = WcfClientProxy <IHelloContract> .InvokeMethod <string>(x => x.Hello(), WcfUtility.CreateTcpClientBinding(), new System.ServiceModel.EndpointAddress(uri)); }
public HelloProxy(string serviceUri) { factory = new WcfCommunicationClientFactory <IHelloContract>(clientBinding: WcfUtility.CreateTcpClientBinding(), servicePartitionResolver: resolver); proxy = new ServicePartitionClient <WcfCommunicationClient <IHelloContract> >( communicationClientFactory: factory, serviceUri: new Uri(serviceUri), listenerName: "WCFServiceEndpoint"); }
static ServiceClient() { communicationClientFactory = new WcfCommunicationClientFactory <ICalculatorService>(clientBinding: WcfUtility.CreateTcpClientBinding()); }
public async static Task Run() { Binding binding = WcfUtility.CreateTcpClientBinding(); // Create a partition resolver IServicePartitionResolver partitionResolver = ServicePartitionResolver.GetDefault(); //var partitionResolver = new ServicePartitionResolver("dctsfpoc.westeurope.cloudapp.azure.com:19080", // "dctsfpoc.westeurope.cloudapp.azure.com:20188", "dctsfpoc.westeurope.cloudapp.azure.com:19000"); // create a WcfCommunicationClientFactory object. var wcfClientFactory = new WcfCommunicationClientFactory <IReferenceDataService> (clientBinding: binding, servicePartitionResolver: partitionResolver); // // Create a client for communicating with the ICalculator service that has been created with the // Singleton partition scheme. // var dataServiceCommunicationClient = new WcfCommunicationClient( wcfClientFactory, new Uri("fabric:/DCT.ILR.Processing.POC/DCT.ILR.Data"), new ServicePartitionKey(1) ); var resolved = partitionResolver.ResolveAsync(new Uri("fabric:/DCT.ILR.Processing.POC/DCT.ILR.Data"), new ServicePartitionKey(1), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), CancellationToken.None).Result; //foreach (var endpoint in resolved.Endpoints) //{ // Console.WriteLine($"Discovered Service Endpoint:'{endpoint.Address}"); //} // ListEndpoints(partitionResolver); // // Call the service to perform the operation. // try { var correlationId = Guid.NewGuid(); //var processTimes = validationServiceCommunicationClient.InvokeWithRetryAsync( // client => client.Channel.GetResults(correlationId)).Result; Console.WriteLine("1. Insert ULns values, 2. Just get results "); var keyValue = Console.ReadKey(); if (keyValue.KeyChar != 50) { await dataServiceCommunicationClient.InvokeWithRetryAsync( client => client.Channel.InsertULNs()); } var ulns = new List <long>() { 1000000027, 1000000035, 1000000043, 1000000051, 1000000078, 1000000272, 1000000280, 1000000299, 1000000302, 1000000310, 1000000477, 1000000485, 1000000493, 1000000647, 1000000655, 1000000671, 1000000779, 1000000787, 1000000795, 1000000841 }; var value1 = new JumpSharding().GetShard("1000000795", 10); var value2 = new JumpSharding().GetShard("1000000795", 10); var validUlns = await dataServiceCommunicationClient.InvokeWithRetryAsync( client => client.Channel.GetULNs(ulns)); Console.WriteLine("1. Insert LARS values, 2. Just get results "); keyValue = Console.ReadKey(); if (keyValue.KeyChar != 50) { await dataServiceCommunicationClient.InvokeWithRetryAsync( client => client.Channel.InsertLARSData()); } var learnAimRefs = new List <string>() { "00100309", "00100325", "00100432", "00100525", "00100533", "00100567", "00100572", "00100573", "00228740", "00228761", "00228762", "00228763", "00228764", "00228787", "00228789", "00228790", "00230643", "00230644", "00230645", "00230646", "00230648", "00230680", "00230684", "00230698", "00230699", "00230703", "00230704", "00230712", "00230713", "00230718", "00230722", "00230761", "00230764", "00243034", "00243035", "00243042", "00243043", "00243045", "00243046", "00243047", "00243054", "00243057", "00243060", "00243064", "00243066", "00243067", "00243068", "00243071", "00243072", "00243073", "00243075", "00243076", "00243077", "00243078", "00243114", "J6018531", "J6018545", "J6018576", "J6018593", "J6018626", "J6018643", "J6018657", "J6018707", "J6018710", "J6018724", "J6018741", "J6018755", "J6018769", "J6018772", "J6018805", "J6018836", "J6018853", "J6018867", "L5068787", "L5068904", "L5070183", "L5070197", "L5070202", "L5070233", "L5070247", "L5070250", "L5070264", "L5070281", "L5070295", "L5070300", "Z0005494", "Z0005495", "Z0005496", "Z0005497", "Z0005498", "Z0005499", "Z0005500", "Z0005501", "Z0005502", "Z0005503", "Z0005504", "Z0005505", "Z0005506", "Z0005507", "Z0005508", "Z0005509", "Z0005510", "Z0005511", "Z0005512", }; var tasksList = new List <Task>(); foreach (var item in learnAimRefs) { tasksList.Add(dataServiceCommunicationClient.InvokeWithRetryAsync( client => client.Channel.GetLARSLearningDeliveriesAsync(new List <string>() { item }))); } try { await Task.WhenAll(tasksList.ToArray()); Console.WriteLine("failed tasks: " + tasksList.Count(x => x.IsFaulted)); //foreach (var task in tasksList) //{ // Console.WriteLine(task.Result); //} } catch (Exception iex) { Console.WriteLine(iex.ToString()); } Console.WriteLine(""); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadLine(); } }
static void Main(string[] args) { var serviceName = new Uri("fabric:/SimpleStoreApplication/ShoppingCartService"); var serviceResolver = new ServicePartitionResolver(() => new FabricClient()); for (var i = 0; i < 10; i++) { var shoppingClient = new Client( new WcfCommunicationClientFactory <IShoppingCartService>(servicePartitionResolver: serviceResolver, clientBinding: WcfUtility.CreateTcpClientBinding()), serviceName, i); shoppingClient.AddItem(new ShoppingCartItem { ProductName = $"XBOX ONE ({i})", UnitPrice = 329.0, Amount = 2 }).Wait(); shoppingClient.AddItem(new ShoppingCartItem { ProductName = $"Halo 5 ({i})", UnitPrice = 59.99, Amount = 1 }).Wait(); PrintPartition(shoppingClient); var list = shoppingClient.GetItems().Result; foreach (var item in list) { Console.WriteLine($"{item.ProductName}: {item.UnitPrice:C2} X {item.Amount} = {item.LineTotal:C2}"); } } Console.ReadKey(); }