New-ServiceFabricServiceFromTemplate

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]
   [-ServicePackageActivationMode <ServicePackageActivationMode>]
   [-ServiceDnsName <String>]
   [-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 is two singleton stateless services of type MyServiceType:

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

Parameters

-ApplicationName

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

Type:Uri
Position:0
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-Force

Forces the command to run without asking for user confirmation.

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

-ServiceDnsName

{{Fill ServiceDnsName Description}}

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

-ServiceName

Specifies the URI of a Service Fabric service.

Type:Uri
Position:1
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-ServicePackageActivationMode

Controls the [hosting model][1] to be used for the service. Valid values are SharedProcess and ExclusiveProcess. The default is SharedProcess.

With SharedProcess activation mode, replicas (or instances) of different services of a given ServiceType will share same ServiceHost. With ExclusiveProcess activation mode, each replica or instance of a service will have its own dedicated ServiceHost. For more details, please see [Service Fabric Hosting Model][1].

Type:ServicePackageActivationMode
Accepted values:SharedProcess, ExclusiveProcess
Position:Named
Default value:None
Required:False
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:2
Default value:None
Required:True
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
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

None

Outputs

System.Object