diff --git a/Services/WcfService/Calculator.Client/App.config b/Services/WcfService/Calculator.Client/App.config index 88fa402..ecdcf8a 100644 --- a/Services/WcfService/Calculator.Client/App.config +++ b/Services/WcfService/Calculator.Client/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/Services/WcfService/Calculator.Client/Calculator.Client.csproj b/Services/WcfService/Calculator.Client/Calculator.Client.csproj index 8203091..4dfbf6d 100644 --- a/Services/WcfService/Calculator.Client/Calculator.Client.csproj +++ b/Services/WcfService/Calculator.Client/Calculator.Client.csproj @@ -9,9 +9,10 @@ Properties Calculator.Client Calculator.Client - v4.5.2 + v4.7.2 512 true + AnyCPU diff --git a/Services/WcfService/Calculator.Common/Calculator.Common.csproj b/Services/WcfService/Calculator.Common/Calculator.Common.csproj index 846d300..a4d40c9 100644 --- a/Services/WcfService/Calculator.Common/Calculator.Common.csproj +++ b/Services/WcfService/Calculator.Common/Calculator.Common.csproj @@ -9,8 +9,9 @@ Properties Calculator.Common Calculator.Common - v4.5.2 + v4.7.2 512 + true diff --git a/Services/WcfService/Calculator.Service/App.config b/Services/WcfService/Calculator.Service/App.config index 6584bb4..82b9527 100644 --- a/Services/WcfService/Calculator.Service/App.config +++ b/Services/WcfService/Calculator.Service/App.config @@ -1,6 +1,18 @@ - + - + - \ No newline at end of file + + + + + + + + + + + + + diff --git a/Services/WcfService/Calculator.Service/Calculator.Service.csproj b/Services/WcfService/Calculator.Service/Calculator.Service.csproj index 5cdb714..3c73867 100644 --- a/Services/WcfService/Calculator.Service/Calculator.Service.csproj +++ b/Services/WcfService/Calculator.Service/Calculator.Service.csproj @@ -9,9 +9,11 @@ Properties Calculator.Service Calculator.Service - v4.5.2 + v4.7.2 512 true + True + true @@ -36,43 +38,71 @@ $(AdditionalFileItemNames);None - - ..\packages\Microsoft.ServiceFabric.Data.2.3.301\lib\net45\Microsoft.ServiceFabric.Data.dll - True + + ..\packages\Microsoft.ServiceFabric.Data.6.1.1653\lib\net452\Microsoft.ServiceFabric.Data.dll + + + ..\packages\Microsoft.ServiceFabric.Data.Extensions.6.1.1653\lib\net452\Microsoft.ServiceFabric.Data.Extensions.dll - ..\packages\Microsoft.ServiceFabric.Data.2.3.301\lib\net45\Microsoft.ServiceFabric.Data.Interfaces.dll - True + ..\packages\Microsoft.ServiceFabric.Data.Interfaces.6.1.1653\lib\net452\Microsoft.ServiceFabric.Data.Interfaces.dll - - ..\packages\Microsoft.ServiceFabric.5.3.301\lib\net45\Microsoft.ServiceFabric.Internal.dll - True + + ..\packages\Microsoft.ServiceFabric.Diagnostics.Internal.6.1.1653\lib\net452\Microsoft.ServiceFabric.Diagnostics.dll - - ..\packages\Microsoft.ServiceFabric.5.3.301\lib\net45\Microsoft.ServiceFabric.Internal.Strings.dll - True + + ..\packages\Microsoft.ServiceFabric.FabricTransport.Internal.6.1.1653\lib\net452\Microsoft.ServiceFabric.FabricTransport.dll - - ..\packages\Microsoft.ServiceFabric.Services.2.3.301\lib\net45\Microsoft.ServiceFabric.Services.dll - True + + ..\packages\Microsoft.ServiceFabric.FabricTransport.Internal.6.1.1653\lib\net452\Microsoft.ServiceFabric.FabricTransport.V2.dll - - ..\packages\Microsoft.ServiceFabric.Services.Wcf.2.3.301\lib\net45\Microsoft.ServiceFabric.Services.Wcf.dll - True + + ..\packages\Microsoft.ServiceFabric.9.1.1653\lib\net452\Microsoft.ServiceFabric.Internal.dll + + + ..\packages\Microsoft.ServiceFabric.9.1.1653\lib\net452\Microsoft.ServiceFabric.Internal.Strings.dll + + + ..\packages\Microsoft.ServiceFabric.9.1.1653\lib\net452\Microsoft.ServiceFabric.Preview.dll + + + ..\packages\Microsoft.ServiceFabric.Data.Extensions.6.1.1653\lib\net452\Microsoft.ServiceFabric.ReliableCollection.Interop.dll + + + ..\packages\Microsoft.ServiceFabric.Services.6.1.1653\lib\net452\Microsoft.ServiceFabric.Services.dll + + + ..\packages\Microsoft.ServiceFabric.Services.Remoting.6.1.1653\lib\net452\Microsoft.ServiceFabric.Services.Remoting.dll + + + ..\packages\Microsoft.ServiceFabric.Services.Wcf.6.1.1653\lib\net45\Microsoft.ServiceFabric.Services.Wcf.dll ..\packages\Microsoft.ServiceFabric.Services.2.3.301\lib\net45\ServiceFabricServiceModel.dll True + + ..\packages\Microsoft.ServiceFabric.9.1.1653\lib\net452\StartupServicesModel.dll + + + ..\packages\System.Buffers.4.5.1\lib\netstandard1.1\System.Buffers.dll + - - ..\packages\Microsoft.ServiceFabric.5.3.301\lib\net45\System.Fabric.dll - True + + ..\packages\Microsoft.ServiceFabric.9.1.1653\lib\net452\System.Fabric.dll - - ..\packages\Microsoft.ServiceFabric.5.3.301\lib\net45\System.Fabric.Strings.dll - True + + ..\packages\Microsoft.ServiceFabric.9.1.1653\lib\net452\System.Fabric.Management.ServiceModel.dll + + + ..\packages\Microsoft.ServiceFabric.9.1.1653\lib\net452\System.Fabric.Strings.dll + + + ..\packages\System.Memory.4.5.3\lib\netstandard1.1\System.Memory.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll diff --git a/Services/WcfService/Calculator.Service/packages.config b/Services/WcfService/Calculator.Service/packages.config index e0c5008..e6bacaa 100644 --- a/Services/WcfService/Calculator.Service/packages.config +++ b/Services/WcfService/Calculator.Service/packages.config @@ -1,7 +1,15 @@  - - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/Services/WcfService/Calculator/CalculatorApp.sfproj b/Services/WcfService/Calculator/CalculatorApp.sfproj index f2df9ab..34038a1 100644 --- a/Services/WcfService/Calculator/CalculatorApp.sfproj +++ b/Services/WcfService/Calculator/CalculatorApp.sfproj @@ -1,9 +1,11 @@  - + 6c3496ae-8fcd-451a-a874-6a89b7ec8545 - 1.3 + 2.1 + 1.7.6 + 1.5 @@ -36,5 +38,9 @@ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Service Fabric Tools\Microsoft.VisualStudio.Azure.Fabric.ApplicationProject.targets - + + + + + \ No newline at end of file diff --git a/Services/WcfService/Calculator/Scripts/Deploy-FabricApplication.ps1 b/Services/WcfService/Calculator/Scripts/Deploy-FabricApplication.ps1 index 9b43f36..2897b10 100644 --- a/Services/WcfService/Calculator/Scripts/Deploy-FabricApplication.ps1 +++ b/Services/WcfService/Calculator/Scripts/Deploy-FabricApplication.ps1 @@ -14,7 +14,7 @@ Path to the file containing the publish profile. .PARAMETER ApplicationPackagePath Path to the folder of the packaged Service Fabric application. -.PARAMETER DeloyOnly +.PARAMETER DeployOnly Indicates that the Service Fabric application should not be created or upgraded after registering the application type. .PARAMETER ApplicationParameter @@ -139,6 +139,7 @@ function Read-PublishProfile $publishProfile.ClusterConnectionParameters = Read-XmlElementAsHashtable $publishProfileXml.PublishProfile.Item("ClusterConnectionParameters") $publishProfile.UpgradeDeployment = Read-XmlElementAsHashtable $publishProfileXml.PublishProfile.Item("UpgradeDeployment") + $publishProfile.CopyPackageParameters = Read-XmlElementAsHashtable $publishProfileXml.PublishProfile.Item("CopyPackageParameters") if ($publishProfileXml.PublishProfile.Item("UpgradeDeployment")) { @@ -196,6 +197,29 @@ Import-Module "$ModuleFolderPath\ServiceFabricSDK.psm1" $IsUpgrade = ($publishProfile.UpgradeDeployment -and $publishProfile.UpgradeDeployment.Enabled -and $OverrideUpgradeBehavior -ne 'VetoUpgrade') -or $OverrideUpgradeBehavior -eq 'ForceUpgrade' +$PublishParameters = @{ + 'ApplicationPackagePath' = $ApplicationPackagePath + 'ApplicationParameterFilePath' = $publishProfile.ApplicationParameterFile + 'ApplicationParameter' = $ApplicationParameter + 'ErrorAction' = 'Stop' +} + +if ($publishProfile.CopyPackageParameters.CopyPackageTimeoutSec) +{ + $PublishParameters['CopyPackageTimeoutSec'] = $publishProfile.CopyPackageParameters.CopyPackageTimeoutSec +} + +if ($publishProfile.CopyPackageParameters.CompressPackage) +{ + $PublishParameters['CompressPackage'] = $publishProfile.CopyPackageParameters.CompressPackage +} + +# CopyPackageTimeoutSec parameter overrides the value from the publish profile +if ($CopyPackageTimeoutSec) +{ + $PublishParameters['CopyPackageTimeoutSec'] = $CopyPackageTimeoutSec +} + if ($IsUpgrade) { $Action = "RegisterAndUpgrade" @@ -212,14 +236,11 @@ if ($IsUpgrade) $UpgradeParameters = @{ UnmonitoredAuto = $true; Force = $true } } - if ($CopyPackageTimeoutSec) - { - Publish-UpgradedServiceFabricApplication -ApplicationPackagePath $ApplicationPackagePath -ApplicationParameterFilePath $publishProfile.ApplicationParameterFile -Action $Action -UpgradeParameters $UpgradeParameters -ApplicationParameter $ApplicationParameter -UnregisterUnusedVersions:$UnregisterUnusedApplicationVersionsAfterUpgrade -CopyPackageTimeoutSec $CopyPackageTimeoutSec -ErrorAction Stop - } - else - { - Publish-UpgradedServiceFabricApplication -ApplicationPackagePath $ApplicationPackagePath -ApplicationParameterFilePath $publishProfile.ApplicationParameterFile -Action $Action -UpgradeParameters $UpgradeParameters -ApplicationParameter $ApplicationParameter -UnregisterUnusedVersions:$UnregisterUnusedApplicationVersionsAfterUpgrade -ErrorAction Stop - } + $PublishParameters['Action'] = $Action + $PublishParameters['UpgradeParameters'] = $UpgradeParameters + $PublishParameters['UnregisterUnusedVersions'] = $UnregisterUnusedApplicationVersionsAfterUpgrade + + Publish-UpgradedServiceFabricApplication @PublishParameters } else { @@ -228,13 +249,10 @@ else { $Action = "Register" } + + $PublishParameters['Action'] = $Action + $PublishParameters['OverwriteBehavior'] = $OverwriteBehavior + $PublishParameters['SkipPackageValidation'] = $SkipPackageValidation - if ($CopyPackageTimeoutSec) - { - Publish-NewServiceFabricApplication -ApplicationPackagePath $ApplicationPackagePath -ApplicationParameterFilePath $publishProfile.ApplicationParameterFile -Action $Action -ApplicationParameter $ApplicationParameter -OverwriteBehavior $OverwriteBehavior -SkipPackageValidation:$SkipPackageValidation -CopyPackageTimeoutSec $CopyPackageTimeoutSec -ErrorAction Stop - } - else - { - Publish-NewServiceFabricApplication -ApplicationPackagePath $ApplicationPackagePath -ApplicationParameterFilePath $publishProfile.ApplicationParameterFile -Action $Action -ApplicationParameter $ApplicationParameter -OverwriteBehavior $OverwriteBehavior -SkipPackageValidation:$SkipPackageValidation -ErrorAction Stop - } + Publish-NewServiceFabricApplication @PublishParameters } \ No newline at end of file diff --git a/Services/WcfService/Calculator/packages.config b/Services/WcfService/Calculator/packages.config index b681b82..ad8665e 100644 --- a/Services/WcfService/Calculator/packages.config +++ b/Services/WcfService/Calculator/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/App.config b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/App.config new file mode 100644 index 0000000..6584bb4 --- /dev/null +++ b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/Calculator.Service.csproj b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/Calculator.Service.csproj new file mode 100644 index 0000000..5cdb714 --- /dev/null +++ b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/Calculator.Service.csproj @@ -0,0 +1,110 @@ + + + + + Debug + x64 + {D0DDD761-0765-40C8-A196-880AE8C688CA} + Exe + Properties + Calculator.Service + Calculator.Service + v4.5.2 + 512 + true + + + true + full + false + bin\x64\Debug\ + DEBUG;TRACE + prompt + x64 + MinimumRecommendedRules.ruleset + + + pdbonly + true + bin\x64\Release\ + TRACE + prompt + x64 + MinimumRecommendedRules.ruleset + + + $(AdditionalFileItemNames);None + + + + ..\packages\Microsoft.ServiceFabric.Data.2.3.301\lib\net45\Microsoft.ServiceFabric.Data.dll + True + + + ..\packages\Microsoft.ServiceFabric.Data.2.3.301\lib\net45\Microsoft.ServiceFabric.Data.Interfaces.dll + True + + + ..\packages\Microsoft.ServiceFabric.5.3.301\lib\net45\Microsoft.ServiceFabric.Internal.dll + True + + + ..\packages\Microsoft.ServiceFabric.5.3.301\lib\net45\Microsoft.ServiceFabric.Internal.Strings.dll + True + + + ..\packages\Microsoft.ServiceFabric.Services.2.3.301\lib\net45\Microsoft.ServiceFabric.Services.dll + True + + + ..\packages\Microsoft.ServiceFabric.Services.Wcf.2.3.301\lib\net45\Microsoft.ServiceFabric.Services.Wcf.dll + True + + + ..\packages\Microsoft.ServiceFabric.Services.2.3.301\lib\net45\ServiceFabricServiceModel.dll + True + + + + + ..\packages\Microsoft.ServiceFabric.5.3.301\lib\net45\System.Fabric.dll + True + + + ..\packages\Microsoft.ServiceFabric.5.3.301\lib\net45\System.Fabric.Strings.dll + True + + + + + + + + + + + + + + + + Designer + + + + + + + {4da78166-7817-49a4-885b-925ca92ae8bb} + Calculator.Common + + + + + \ No newline at end of file diff --git a/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/CalculatorService.cs b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/CalculatorService.cs new file mode 100644 index 0000000..5fdc8fe --- /dev/null +++ b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/CalculatorService.cs @@ -0,0 +1,32 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. +// ------------------------------------------------------------ + +namespace Calculator.Service +{ + using System.Fabric; + using System.ServiceModel; + using System.Threading.Tasks; + using Calculator.Common; + + // Service class which implements the service contract. + [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)] + public class CalculatorService : ICalculator + { + private readonly ServiceContext context; + + public CalculatorService(ServiceContext context) + { + this.context = context; + } + + public Task Add(double n1, double n2) + { + var result = n1 + n2; + ServiceEventSource.Current.ServiceMessage(this.context, "Received Add({0},{1})", n1, n2); + ServiceEventSource.Current.ServiceMessage(this.context, "Return: {0}", result); + return Task.FromResult(result); + } + } +} \ No newline at end of file diff --git a/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/PackageRoot/Config/Settings.xml b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/PackageRoot/Config/Settings.xml new file mode 100644 index 0000000..ad84ffd --- /dev/null +++ b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/PackageRoot/Config/Settings.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/PackageRoot/ServiceManifest.xml b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/PackageRoot/ServiceManifest.xml new file mode 100644 index 0000000..57305d8 --- /dev/null +++ b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/PackageRoot/ServiceManifest.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + Calculator.Service.exe + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/Program.cs b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/Program.cs new file mode 100644 index 0000000..87695e1 --- /dev/null +++ b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/Program.cs @@ -0,0 +1,43 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. +// ------------------------------------------------------------ + +namespace Calculator.Service +{ + using System; + using System.Diagnostics; + using System.Threading; + using Microsoft.ServiceFabric.Services.Runtime; + + internal static class Program + { + /// + /// This is the entry point of the service host process. + /// + private static void Main() + { + try + { + // The ServiceManifest.XML file defines one or more service type names. + // Registering a service maps a service type name to a .NET type. + // When Service Fabric creates an instance of this service type, + // an instance of the class is created in this host process. + + ServiceRuntime.RegisterServiceAsync( + "CalculatorServiceType", + context => new Service(context)).GetAwaiter().GetResult(); + + ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(Service).Name); + + // Prevents this host process from terminating so services keep running. + Thread.Sleep(Timeout.Infinite); + } + catch (Exception e) + { + ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString()); + throw; + } + } + } +} \ No newline at end of file diff --git a/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/Properties/AssemblyInfo.cs b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d9e14d9 --- /dev/null +++ b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/Properties/AssemblyInfo.cs @@ -0,0 +1,44 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. +// ------------------------------------------------------------ + +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. + +[assembly: AssemblyTitle("Calculator.Service")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Calculator.Service")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. + +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM + +[assembly: Guid("d0ddd761-0765-40c8-a196-880ae8c688ca")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/Service.cs b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/Service.cs new file mode 100644 index 0000000..46d3c27 --- /dev/null +++ b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/Service.cs @@ -0,0 +1,42 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. +// ------------------------------------------------------------ + +namespace Calculator.Service +{ + using System.Collections.Generic; + using System.Fabric; + using System.ServiceModel; + using Calculator.Common; + using Microsoft.ServiceFabric.Services.Communication.Runtime; + using Microsoft.ServiceFabric.Services.Communication.Wcf.Runtime; + using Microsoft.ServiceFabric.Services.Runtime; + + /// + /// An instance of this class is created for each service instance by the Service Fabric runtime. + /// + internal sealed class Service : StatelessService + { + public Service(StatelessServiceContext context) + : base(context) + { + } + + //Using SOAP Http Binding. It reads the port from EndpointReseourceName specified in ServiceManifest file. + + protected override IEnumerable CreateServiceInstanceListeners() + { + // create an return WCF based communication listener that hosts WCF Calculator Service. + return new[] + { + new ServiceInstanceListener( + c => new WcfCommunicationListener( + c, + new CalculatorService(c), + new BasicHttpBinding(), + endpointResourceName: "ServiceEndpoint")) + }; + } + } +} \ No newline at end of file diff --git a/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/ServiceEventSource.cs b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/ServiceEventSource.cs new file mode 100644 index 0000000..313f588 --- /dev/null +++ b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/ServiceEventSource.cs @@ -0,0 +1,214 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. +// ------------------------------------------------------------ + +namespace Calculator.Service +{ + using System; + using System.Diagnostics.Tracing; + using System.Fabric; + using System.Threading.Tasks; + using Microsoft.ServiceFabric.Services.Runtime; + + [EventSource(Name = "MyCompany-Calculator-Service")] + internal sealed class ServiceEventSource : EventSource + { + public static readonly ServiceEventSource Current = new ServiceEventSource(); + + static ServiceEventSource() + { + // A workaround for the problem where ETW activities do not get tracked until Tasks infrastructure is initialized. + // This problem will be fixed in .NET Framework 4.6.2. + Task.Run(() => { }).Wait(); + } + + // Instance constructor is private to enforce singleton semantics + private ServiceEventSource() + { + } + + #region Keywords + + // Event keywords can be used to categorize events. + // Each keyword is a bit flag. A single event can be associated with multiple keywords (via EventAttribute.Keywords property). + // Keywords must be defined as a public class named 'Keywords' inside EventSource that uses them. + public static class Keywords + { + public const EventKeywords Requests = (EventKeywords) 0x1L; + public const EventKeywords ServiceInitialization = (EventKeywords) 0x2L; + } + + #endregion + + #region Events + + // Define an instance method for each event you want to record and apply an [Event] attribute to it. + // The method name is the name of the event. + // Pass any parameters you want to record with the event (only primitive integer types, DateTime, Guid & string are allowed). + // Each event method implementation should check whether the event source is enabled, and if it is, call WriteEvent() method to raise the event. + // The number and types of arguments passed to every event method must exactly match what is passed to WriteEvent(). + // Put [NonEvent] attribute on all methods that do not define an event. + // For more information see https://msdn.microsoft.com/en-us/library/system.diagnostics.tracing.eventsource.aspx + + [NonEvent] + public void Message(string message, params object[] args) + { + if (this.IsEnabled()) + { + var finalMessage = string.Format(message, args); + this.Message(finalMessage); + } + } + + private const int MessageEventId = 1; + + [Event(MessageEventId, Level = EventLevel.Informational, Message = "{0}")] + public void Message(string message) + { + if (this.IsEnabled()) + { + this.WriteEvent(MessageEventId, message); + } + } + + [NonEvent] + public void ServiceMessage(StatelessService service, string message, params object[] args) + { + this.ServiceMessage(service.Context, message, args); + } + + [NonEvent] + public void ServiceMessage(ServiceContext context, string message, params object[] args) + { + if (this.IsEnabled()) + { + var finalMessage = string.Format(message, args); + this.ServiceMessage( + context.ServiceName.ToString(), + context.ServiceTypeName, + context.ReplicaOrInstanceId, + context.PartitionId, + context.CodePackageActivationContext.ApplicationName, + context.CodePackageActivationContext.ApplicationTypeName, + context.NodeContext.NodeName, + finalMessage); + } + } + + // For very high-frequency events it might be advantageous to raise events using WriteEventCore API. + // This results in more efficient parameter handling, but requires explicit allocation of EventData structure and unsafe code. + // To enable this code path, define UNSAFE conditional compilation symbol and turn on unsafe code support in project properties. + private const int ServiceMessageEventId = 2; + + [Event(ServiceMessageEventId, Level = EventLevel.Informational, Message = "{7}")] + private +#if UNSAFE + unsafe +#endif + void ServiceMessage( + string serviceName, + string serviceTypeName, + long replicaOrInstanceId, + Guid partitionId, + string applicationName, + string applicationTypeName, + string nodeName, + string message) + { +#if !UNSAFE + this.WriteEvent( + ServiceMessageEventId, + serviceName, + serviceTypeName, + replicaOrInstanceId, + partitionId, + applicationName, + applicationTypeName, + nodeName, + message); +#else + const int numArgs = 8; + fixed (char* pServiceName = serviceName, pServiceTypeName = serviceTypeName, pApplicationName = applicationName, pApplicationTypeName = applicationTypeName, pNodeName = nodeName, pMessage = message) + { + EventData* eventData = stackalloc EventData[numArgs]; + eventData[0] = new EventData { DataPointer = (IntPtr) pServiceName, Size = SizeInBytes(serviceName) }; + eventData[1] = new EventData { DataPointer = (IntPtr) pServiceTypeName, Size = SizeInBytes(serviceTypeName) }; + eventData[2] = new EventData { DataPointer = (IntPtr) (&replicaOrInstanceId), Size = sizeof(long) }; + eventData[3] = new EventData { DataPointer = (IntPtr) (&partitionId), Size = sizeof(Guid) }; + eventData[4] = new EventData { DataPointer = (IntPtr) pApplicationName, Size = SizeInBytes(applicationName) }; + eventData[5] = new EventData { DataPointer = (IntPtr) pApplicationTypeName, Size = SizeInBytes(applicationTypeName) }; + eventData[6] = new EventData { DataPointer = (IntPtr) pNodeName, Size = SizeInBytes(nodeName) }; + eventData[7] = new EventData { DataPointer = (IntPtr) pMessage, Size = SizeInBytes(message) }; + + WriteEventCore(ServiceMessageEventId, numArgs, eventData); + } +#endif + } + + private const int ServiceTypeRegisteredEventId = 3; + + [Event(ServiceTypeRegisteredEventId, Level = EventLevel.Informational, Message = "Service host process {0} registered service type {1}", + Keywords = Keywords.ServiceInitialization)] + public void ServiceTypeRegistered(int hostProcessId, string serviceType) + { + this.WriteEvent(ServiceTypeRegisteredEventId, hostProcessId, serviceType); + } + + private const int ServiceHostInitializationFailedEventId = 4; + + [Event(ServiceHostInitializationFailedEventId, Level = EventLevel.Error, Message = "Service host initialization failed", + Keywords = Keywords.ServiceInitialization)] + public void ServiceHostInitializationFailed(string exception) + { + this.WriteEvent(ServiceHostInitializationFailedEventId, exception); + } + + // A pair of events sharing the same name prefix with a "Start"/"Stop" suffix implicitly marks boundaries of an event tracing activity. + // These activities can be automatically picked up by debugging and profiling tools, which can compute their execution time, child activities, + // and other statistics. + private const int ServiceRequestStartEventId = 5; + + [Event(ServiceRequestStartEventId, Level = EventLevel.Informational, Message = "Service request '{0}' started", Keywords = Keywords.Requests)] + public void ServiceRequestStart(string requestTypeName) + { + this.WriteEvent(ServiceRequestStartEventId, requestTypeName); + } + + private const int ServiceRequestStopEventId = 6; + + [Event(ServiceRequestStopEventId, Level = EventLevel.Informational, Message = "Service request '{0}' finished", Keywords = Keywords.Requests)] + public void ServiceRequestStop(string requestTypeName) + { + this.WriteEvent(ServiceRequestStopEventId, requestTypeName); + } + + private const int ServiceRequestFailedEventId = 7; + + [Event(ServiceRequestFailedEventId, Level = EventLevel.Error, Message = "Service request '{0}' failed", Keywords = Keywords.Requests)] + public void ServiceRequestFailed(string requestTypeName, string exception) + { + this.WriteEvent(ServiceRequestFailedEventId, exception); + } + + #endregion + + #region Private methods + +#if UNSAFE + private int SizeInBytes(string s) + { + if (s == null) + { + return 0; + } + else + { + return (s.Length + 1) * sizeof(char); + } + } +#endif + + #endregion + } +} \ No newline at end of file diff --git a/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/packages.config b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/packages.config new file mode 100644 index 0000000..e0c5008 --- /dev/null +++ b/Services/WcfService/ServiceFabricServicesBackup/Calculator.Service/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Services/WordCount/README.md b/Services/WordCount/README.md new file mode 100644 index 0000000..c319822 --- /dev/null +++ b/Services/WordCount/README.md @@ -0,0 +1,22 @@ +## Run this sample + +Alphabet partitions is an intro to partitioning stateful services in Service Fabric. It uses letters of the alphabet as partition keys into a stateful service with 26 partitions - one for each letter of the alphabet. + +To run this services: + +1. Open the .sln solution file in Visual Studio 2019 or 2022 +2. Install latest runtime and SDK from here: https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-get-started +3. Set WordCount as Startup Project +4. Press F5 to run + +You can access the application in a web browser by going to: + +**http://localhost:8081/WordCount/ + + +Try different values for lastname to see data get sent to different partitions. + +## Next Steps + +- [Read more about ReliableServices and Reliable Collections ](https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-introduction) + \ No newline at end of file diff --git a/Services/WordCount/WordCount.Common/packages.config b/Services/WordCount/WordCount.Common/packages.config index e82a2b2..8c39b97 100644 --- a/Services/WordCount/WordCount.Common/packages.config +++ b/Services/WordCount/WordCount.Common/packages.config @@ -1,9 +1,9 @@  - - - - - + + + + + \ No newline at end of file diff --git a/Services/WordCount/WordCount.Service/WordCount.Service.csproj b/Services/WordCount/WordCount.Service/WordCount.Service.csproj index b6564c8..bc84dc5 100644 --- a/Services/WordCount/WordCount.Service/WordCount.Service.csproj +++ b/Services/WordCount/WordCount.Service/WordCount.Service.csproj @@ -11,6 +11,7 @@ WordCount.Service v4.5 512 + True x64 diff --git a/Services/WordCount/WordCount.Service/packages.config b/Services/WordCount/WordCount.Service/packages.config index 4044a52..95649c6 100644 --- a/Services/WordCount/WordCount.Service/packages.config +++ b/Services/WordCount/WordCount.Service/packages.config @@ -1,18 +1,18 @@  - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Services/WordCount/WordCount.WebService/HttpExceptionHandler.cs b/Services/WordCount/WordCount.WebService/HttpExceptionHandler.cs index 40e980c..6b14b9d 100644 --- a/Services/WordCount/WordCount.WebService/HttpExceptionHandler.cs +++ b/Services/WordCount/WordCount.WebService/HttpExceptionHandler.cs @@ -7,6 +7,7 @@ namespace WordCount.WebService { using System; using System.Net; + using System.Net.Http; using System.Net.Sockets; using Microsoft.ServiceFabric.Services.Communication.Client; @@ -29,6 +30,11 @@ public bool TryHandleException(ExceptionInformation exceptionInformation, Operat result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, false, retrySettings, retrySettings.DefaultMaxRetryCount); return true; } + else if (exceptionInformation.Exception is HttpRequestException) + { + result = new ExceptionHandlingRetryResult(exceptionInformation.Exception, false, retrySettings, retrySettings.DefaultMaxRetryCount); + return true; + } WebException we = exceptionInformation.Exception as WebException; diff --git a/Services/WordCount/WordCount.WebService/WordCount.WebService.csproj b/Services/WordCount/WordCount.WebService/WordCount.WebService.csproj index 1db115f..206a206 100644 --- a/Services/WordCount/WordCount.WebService/WordCount.WebService.csproj +++ b/Services/WordCount/WordCount.WebService/WordCount.WebService.csproj @@ -11,6 +11,7 @@ WordCount.WebService v4.5 512 + True x64 diff --git a/Services/WordCount/WordCount.WebService/packages.config b/Services/WordCount/WordCount.WebService/packages.config index c98ce96..01ae522 100644 --- a/Services/WordCount/WordCount.WebService/packages.config +++ b/Services/WordCount/WordCount.WebService/packages.config @@ -1,17 +1,17 @@  - - - - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/Services/WordCount/WordCount/Scripts/Deploy-FabricApplication.ps1 b/Services/WordCount/WordCount/Scripts/Deploy-FabricApplication.ps1 index 6cedbf7..74e3990 100644 --- a/Services/WordCount/WordCount/Scripts/Deploy-FabricApplication.ps1 +++ b/Services/WordCount/WordCount/Scripts/Deploy-FabricApplication.ps1 @@ -14,7 +14,7 @@ Path to the file containing the publish profile. .PARAMETER ApplicationPackagePath Path to the folder of the packaged Service Fabric application. -.PARAMETER DeloyOnly +.PARAMETER DeployOnly Indicates that the Service Fabric application should not be created or upgraded after registering the application type. .PARAMETER ApplicationParameter @@ -25,7 +25,7 @@ Indicates whether to unregister any unused application versions that exist after .PARAMETER OverrideUpgradeBehavior Indicates the behavior used to override the upgrade settings specified by the publish profile. -'None' indicates that the upgrade settings will not be overriden. +'None' indicates that the upgrade settings will not be overridden. 'ForceUpgrade' indicates that an upgrade will occur with default settings, regardless of what is specified in the publish profile. 'VetoUpgrade' indicates that an upgrade will not occur, regardless of what is specified in the publish profile. @@ -44,6 +44,9 @@ Switch signaling whether the package should be validated or not before deploymen .PARAMETER SecurityToken A security token for authentication to cluster management endpoints. Used for silent authentication to clusters that are protected by Azure Active Directory. +.PARAMETER CopyPackageTimeoutSec +Timeout in seconds for copying application package to image store. + .EXAMPLE . Scripts\Deploy-FabricApplication.ps1 -ApplicationPackagePath 'pkg\Debug' @@ -92,7 +95,10 @@ Param $SkipPackageValidation, [String] - $SecurityToken + $SecurityToken, + + [int] + $CopyPackageTimeoutSec ) function Read-XmlElementAsHashtable @@ -133,6 +139,7 @@ function Read-PublishProfile $publishProfile.ClusterConnectionParameters = Read-XmlElementAsHashtable $publishProfileXml.PublishProfile.Item("ClusterConnectionParameters") $publishProfile.UpgradeDeployment = Read-XmlElementAsHashtable $publishProfileXml.PublishProfile.Item("UpgradeDeployment") + $publishProfile.CopyPackageParameters = Read-XmlElementAsHashtable $publishProfileXml.PublishProfile.Item("CopyPackageParameters") if ($publishProfileXml.PublishProfile.Item("UpgradeDeployment")) { @@ -190,6 +197,29 @@ Import-Module "$ModuleFolderPath\ServiceFabricSDK.psm1" $IsUpgrade = ($publishProfile.UpgradeDeployment -and $publishProfile.UpgradeDeployment.Enabled -and $OverrideUpgradeBehavior -ne 'VetoUpgrade') -or $OverrideUpgradeBehavior -eq 'ForceUpgrade' +$PublishParameters = @{ + 'ApplicationPackagePath' = $ApplicationPackagePath + 'ApplicationParameterFilePath' = $publishProfile.ApplicationParameterFile + 'ApplicationParameter' = $ApplicationParameter + 'ErrorAction' = 'Stop' +} + +if ($publishProfile.CopyPackageParameters.CopyPackageTimeoutSec) +{ + $PublishParameters['CopyPackageTimeoutSec'] = $publishProfile.CopyPackageParameters.CopyPackageTimeoutSec +} + +if ($publishProfile.CopyPackageParameters.CompressPackage) +{ + $PublishParameters['CompressPackage'] = $publishProfile.CopyPackageParameters.CompressPackage +} + +# CopyPackageTimeoutSec parameter overrides the value from the publish profile +if ($CopyPackageTimeoutSec) +{ + $PublishParameters['CopyPackageTimeoutSec'] = $CopyPackageTimeoutSec +} + if ($IsUpgrade) { $Action = "RegisterAndUpgrade" @@ -206,7 +236,11 @@ if ($IsUpgrade) $UpgradeParameters = @{ UnmonitoredAuto = $true; Force = $true } } - Publish-UpgradedServiceFabricApplication -ApplicationPackagePath $ApplicationPackagePath -ApplicationParameterFilePath $publishProfile.ApplicationParameterFile -Action $Action -UpgradeParameters $UpgradeParameters -ApplicationParameter $ApplicationParameter -UnregisterUnusedVersions:$UnregisterUnusedApplicationVersionsAfterUpgrade -ErrorAction Stop + $PublishParameters['Action'] = $Action + $PublishParameters['UpgradeParameters'] = $UpgradeParameters + $PublishParameters['UnregisterUnusedVersions'] = $UnregisterUnusedApplicationVersionsAfterUpgrade + + Publish-UpgradedServiceFabricApplication @PublishParameters } else { @@ -215,6 +249,10 @@ else { $Action = "Register" } + + $PublishParameters['Action'] = $Action + $PublishParameters['OverwriteBehavior'] = $OverwriteBehavior + $PublishParameters['SkipPackageValidation'] = $SkipPackageValidation - Publish-NewServiceFabricApplication -ApplicationPackagePath $ApplicationPackagePath -ApplicationParameterFilePath $publishProfile.ApplicationParameterFile -Action $Action -ApplicationParameter $ApplicationParameter -OverwriteBehavior $OverwriteBehavior -SkipPackageValidation:$SkipPackageValidation -ErrorAction Stop + Publish-NewServiceFabricApplication @PublishParameters } \ No newline at end of file diff --git a/Services/WordCount/WordCount/WordCount.sfproj b/Services/WordCount/WordCount/WordCount.sfproj index dbe5505..9b6f658 100644 --- a/Services/WordCount/WordCount/WordCount.sfproj +++ b/Services/WordCount/WordCount/WordCount.sfproj @@ -1,11 +1,13 @@  - + de5d59b0-1752-4cf7-a980-4edddba8935e - 1.2 + 2.1 v4.5 true + 1.7.7 + 1.5 @@ -39,5 +41,9 @@ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Service Fabric Tools\Microsoft.VisualStudio.Azure.Fabric.ApplicationProject.targets - + + + + + \ No newline at end of file diff --git a/Services/WordCount/WordCount/packages.config b/Services/WordCount/WordCount/packages.config index 2c11cca..e500a50 100644 --- a/Services/WordCount/WordCount/packages.config +++ b/Services/WordCount/WordCount/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file