CreateService


Description

This method creates a new service.

Parameters

Parameter

Type

Description

service

Service

The service object being created.

context

Context

Specifies information about how the method will be called.

policy

Policy

Specifies the set of behaviors and behavior options to be applied during the operation.


Interfaces

 

Examples

The following C# example creates a service with the key value “NEW-SUPRT-SRVC0010”. The Key, Type, Description, and UofMScheduleKey properties are populated, and all other properties are left as default values.

 Legacy endpoint

using System;
using System.Collections.Generic;
using System.Text;
using DynamicsGPWebServiceSample.DynamicsGPService;

namespace DynamicsGPWebServiceSample
{
	class Program
	{
		static void Main(string[] args)
		{
			CompanyKey companyKey;
			Context context;
			ItemKey itemKey;
			UofMScheduleKey unitKey;
			Service service;
			Policy serviceCreatePolicy;

			// Create an instance of the service
			DynamicsGP wsDynamicsGP = new DynamicsGP();

			// Be sure the default credentials are used
			wsDynamicsGP.UseDefaultCredentials = true;

			// Create a context with which to call the service
			context = new Context();

			// Specify which company to use (sample company)
			companyKey = new CompanyKey();
			companyKey.Id = (-1);

			// Set up the context object
			context.OrganizationKey = (OrganizationKey)companyKey;

			// Create an Item Key object to identify the service
			itemKey = new ItemKey();
			itemKey.Id = "NEW-SUPRT-SRVC0010";

			// Create a unit of measure schedule key
			unitKey = new UofMScheduleKey();
			unitKey.Id = "HR";

			// Create a service object
			service = new Service();

			// Populate the service's key, type, description and UofMScheduleKey properties
			service.Key = itemKey;
			service.Type = ItemType.Service;
			service.Description = "New Support plan";
			service.UofMScheduleKey = unitKey;

			// Get the create policy for services
			serviceCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateService", context);

			// Create the service
			wsDynamicsGP.CreateService(service, context, serviceCreatePolicy);
	}
}
}

 Native endpoint

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DynamicsGPWebServiceSample.DynamicsGPService;

namespace DynamicsGPWebServiceSample
{
	class Program
	{
		static void Main(string[] args)
		{
			CompanyKey companyKey;
			Context context;
			ItemKey itemKey;
			UofMScheduleKey unitKey;
			Service service;
			Policy serviceCreatePolicy;

			// Create an instance of the service
			DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();

			// Create a context with which to call the service
			context = new Context();

			// Specify which company to use (sample company)
			companyKey = new CompanyKey();
			companyKey.Id = (-1);

			// Set up the context object
			context.OrganizationKey = (OrganizationKey)companyKey;

			// Create an Item Key object to identify the service
			itemKey = new ItemKey();
			itemKey.Id = "NEW-SUPRT-SRVC0010";

			// Create a unit of measure schedule key
			unitKey = new UofMScheduleKey();
			unitKey.Id = "HR";

			// Create a service object
			service = new Service();

			// Populate the service's key, type, description and UofMScheduleKey properties
			service.Key = itemKey;
			service.Type = ItemType.Service;
			service.Description = "New Support plan";
			service.UofMScheduleKey = unitKey;

			// Get the create policy for services
			serviceCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateService", context);

			// Create the service
			wsDynamicsGP.CreateService(service, context, serviceCreatePolicy);

			// Close the service
			if(wsDynamicsGP.State != CommunicationState.Faulted)
			{
				wsDynamicsGP.Close();
		}
	}
}
}


Documentation Feedback