Exemple #1
0
        /// <summary>
        /// This is the main entry point for your service instance.
        /// </summary>
        /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service instance.</param>
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            ServiceProxyFactory factory = new ServiceProxyFactory(handler =>
                                                                  new FabricTransportServiceRemotingClientFactory(new FabricTransportRemotingSettings
            {
                UseWrappedMessage = true
            }));

            ISampleService sampleService = factory.CreateNonIServiceProxy <ISampleService>(
                new Uri("fabric:/SFRemotingSerializationIssue/SampleService"));

            while (true)
            {
                cancellationToken.ThrowIfCancellationRequested();

                try
                {
                    int simpleValue = await sampleService.SimpleTypeShouldWorkV1V2Async(100);

                    Console.WriteLine($"SimpleType works: '{simpleValue}'.");

                    int wrappedValue = await sampleService.GenericStructShouldWorkV1V2Async(100);

                    Console.WriteLine($"GenericType works: '{wrappedValue}'.");

                    // commented out as V2 cannot generate data contract if there are two methods with different
                    // types that resolve to same contract name
                    //List<int> collectionValue = await sampleService.SpecificCollectionTypeShouldWorkV1V2Async(new[] { 1, 2, 3 });
                    //Console.WriteLine($"CollectionType works: '{string.Join(", ", collectionValue)}'.");

                    IEnumerable <int> enumerableValue =
                        await sampleService.KnownCollectionInterfaceShouldWorkV21(new[] { 1, 2, 3 });

                    Console.WriteLine($"CollectionInterface works: '{string.Join(", ", enumerableValue)}'.");
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine($"Caught exception: {ex}");
                }

                await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
            }
        }