Skip to content
Tsuyoshi Ushio edited this page Aug 9, 2016 · 7 revisions

Programming Microsoft Azure Service Fabric source code revision history

  1. Chapter 2 The First Version

1.1. P34: ServiceInstanceListener

CalculatorService.cs

         protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
         {
              return new[]
              {
                  new ServiceInstanceListener(context =>
                     this.CreateServiceRemotingListener(context))
              };
          }

Code Sample

1.2. P38: RegisterServiceType

Program.cs

                ServiceRuntime.RegisterServiceAsync("CalculatorServiceType",
                    context => new CalculatorService(context)).GetAwaiter().GetResult();

[Code Sample] (https://github.com/TsuyoshiUshio/AzureServiceFabricSample/blob/4cf37a68634018072b2efeaa6d47709820067e96/Chapter02/CalculatorApplication/CalculatorService/Program.cs#L24-L25)

  1. Chapter 2 The Second version

P39: Add / Subtract methods

        public Task<string> Add(int a, int b)
        {
            return Task.FromResult<string>(string.Format("Instance {0} returns: {1}",
                this.Context.InstanceId,
                a + b));
        }

        public Task<string> Subtract(int a, int b)
        {
            return Task.FromResult<string>(string.Format("Instance {0} returns: {1}",
                this.Context.InstanceId,
                a - b));
        }

Code Sample

  1. Chapter 2 The third version

P42: CreateServiceInstanceListeners()

        protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            return new[]
            {
                new ServiceInstanceListener(context =>
                    new WcfCommunicationListener<ICalculatorService>(
                        wcfServiceObject:this,
                        serviceContext:context,
                        endpointResourceName: "ServiceEndpoint",
                        listenerBinding: WcfUtility.CreateTcpListenerBinding()
                    )
            )};
        }

Code Sample

P48: OpenAsync

This revision is enable us to route http://localhost:80/webapp/api/... as the book says.

        public OwinCommunicationListener(IOwinAppBuilder startup, ServiceContext serviceContext, string appRoot)
        {
            this.startup = startup;
            this.serviceContext = serviceContext;
            this.appRoot = appRoot;
        }
        public Task<string> OpenAsync(CancellationToken cancellationToken)
        {
            EndpointResourceDescription serviceEndpoint = this.serviceContext.CodePackageActivationContext.GetEndpoint("ServiceEndpoint");
            int port = serviceEndpoint.Port;
            this.listeningAddress = String.Format("http://+:{0}/{1}/", port, appRoot);
                             :

Code Sample

Clone this wiki locally