New-​Service​Fabric​Service​From​Template

If the application manifest has defined a service templates section, then this command can be used to create new services with service description parameters populated from the template.

Syntax

New-ServiceFabricServiceFromTemplate
   [-ApplicationName] <Uri>
   [-ServiceName] <Uri>
   [-ServiceTypeName] <String>
   [-Force]
   [-TimeoutSec <Int32>]
   [<CommonParameters>]

Description

New-ServiceFabricService has several mandatory parameters that describe the service being created. Service templates in the application manifest can be used to specify service description parameters on a per service type basis. The service description schema in the service template section is the same as the service description schema for default services. This allows creating new services of a particular service type without specifying parameters that would otherwise have been mandatory for New-ServiceFabricService.

Services created using a service template behave identically to services created using New-ServiceFabricService. They can be upgraded, updated, and removed using the same workflows.

Before you perform any operation on a Service Fabric cluster, establish a connection to the cluster by using the Connect-ServiceFabricCluster cmdlet.

Examples

Example 1: Create a service from a service template

Given the following application and service manifests:

<?xml version="1.0" encoding="utf-8" ?>
<ApplicationManifest
      ApplicationTypeName="MyApplicationType"
      ApplicationTypeVersion="AppManifestVersion1"
      xmlns="http://schemas.microsoft.com/2011/01/fabric"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Description>An example application manifest</Description>
  <ServiceManifestImport>
    <ServiceManifestRef ServiceManifestName="MyServiceManifest" ServiceManifestVersion="SvcManifestVersion1"/>
  </ServiceManifestImport>
  <ServiceTemplates>
     <StatelessService ServiceTypeName="MyServiceType" InstanceCount="-1">
         <SingletonPartition/>
     </StatelessService>
  </ServiceTemplates>
</ApplicationManifest>

<?xml version="1.0" encoding="utf-8" ?>
<ServiceManifest Name="MyServiceManifest" Version="SvcManifestVersion1" xmlns="http://schemas.microsoft.com/2011/01/fabric" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Description>An example service manifest</Description>
  <ServiceTypes>
    <StatelessServiceType ServiceTypeName="MyServiceType" />
  </ServiceTypes>
  <CodePackage Name="MyCode" Version="CodeVersion1">
    <EntryPoint>
      <ExeHost>
        <Program>MyServiceHost.exe</Program>
      </ExeHost>
    </EntryPoint>
  </CodePackage>
</ServiceManifest>

The following command creates a Service Fabric service using the service template for service type MyServiceType defined in the application manifest:



PS C:> New-ServiceFabricServiceFromTemplate -ApplicationName fabric:/myapp -ServiceName fabric:/myapp/myservice1 -ServiceTypeName MyServiceType

Multiple service instances can be created using the same service template. After additionally running the following command, there will be two singleton stateless services of type MyServiceType:

PS C:> New-ServiceFabricServiceFromTemplate -ApplicationName fabric:/myapp -ServiceName fabric:/myapp/myservice2 -ServiceTypeName MyServiceType

Required Parameters

-ApplicationName

Specifies the Uniform Resource Identifier (URI) of a Service Fabric application to create the service in.

Type:Uri
Position:1
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ServiceName

Specifies the URI of a Service Fabric service.

Type:Uri
Position:2
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ServiceTypeName

Specifies the name of a Service Fabric service type for which there is a service template defined in the application manifest.

Type:String
Position:3
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Optional Parameters

-Force

Forces the command to run without asking for user confirmation.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-TimeoutSec

Specifies the time-out period, in seconds, for the operation.

Type:Int32
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Inputs

None

Outputs

System.Object