Follow a lead from creation through closure

A lead record in Microsoft Dynamics CRM Online represents a potential customer who must be qualified or disqualified as a sales opportunity. You can use leads to manage potential sales from the point at which you become aware of a customer's interest through the successful sale.

The following diagram illustrates the ways that you can create a lead and convert it to several different record types.

Lead diagram

There are several ways that you can create a lead in Microsoft Dynamics CRM Online:

After you create the lead, you can convert it into any of the following three record types:

  • Account
  • Contact
  • Opportunity

When you convert the lead to an opportunity, you can also choose to link the new opportunity to the new accounts or contacts you may have created, or to an existing account or contact in your Microsoft Dynamics CRM Online database.

Follow an opportunity from creation through closure

An opportunity is a potential sale or possible revenue from an account or contact.

The following diagram illustrates the ways that you can create an opportunity and close it when the potential customer decides whether to move forward with the sale.

Opportunity diagram

There are several ways that you can create an opportunity in Microsoft Dynamics CRM:

When you know whether or not the customer is going to move forward with the sale, you can close the opportunity with a status of either Won or Lost.

Walkthrough: Using the Discovery Service with Active Directory Authentication

[Applies to: Microsoft Dynamics CRM 4.0]

This walkthrough demonstrates how to use the Discovery Web service to find the correct CrmService Web service endpoint for your organization. This is for an on-premise installation of Microsoft Dynamics CRM. For more information on the Discovery Web service, see Web Services: CrmDiscoveryService.

During this walkthrough you will learn how to do the following:

  • Use Microsoft Visual Studio 2005 to create a console application that uses the Microsoft Dynamics CRM Web services.
  • Use Active Directory authentication for interacting with the Microsoft Dynamics CRM Web services.

This walkthrough utilizes Microsoft Visual C# sample code only. However, a Microsoft Visual Basic .NET version of the code can be found at SDK\Walkthroughs\Authentication\VB\ActiveDirectory.

Prerequisites

In order to complete this walkthrough, you will need the following:

  • Access to a Microsoft Dynamics CRM 4.0 server.
  • A Microsoft Dynamics CRM system account.
  • Visual Studio 2005.

Creating a Visual Studio 2005 Solution

You will use a Visual Studio 2005 solution to build your project code.

To create a Visual Studio 2005 solution

1. In Microsoft Visual Studio 2005, on the File menu, point to New, and then click Project to open the New Project dialog box.

2. In the Project types pane, select Visual C#.

3. In the Templates pane, click Console Application.

4. Type a name for your project and then click OK.

While this walkthrough only shows the Visual C# code for the project, a VB.NET version of the code can be found in the SDK\Walkthroughs\Authentication\VB\ActiveDirectory folder.

Adding Web References

You need to add Web references to the required Microsoft Dynamics CRM Web services. By adding these Web references, you are making the Web service proxy namespaces accessible to your project.

To add the CrmDiscoveryService Web service reference

1. In the Solution Explorer window, right-click your project name and choose Add Web Reference.

2. In the Add Web Reference wizard, type the URL for the CrmDiscoveryService Web service in the URL box, using the name and port number for your Microsoft Dynamics CRM server, and then click Go. For example:

3. http://<servername:port>/mscrmservices/2007/AD/CrmDiscoveryService.asmx

4. When the CrmDiscoveryService Web service is found, change the text in the Web reference name box to CrmSdk.Discovery and then click Add Reference.

To add the CrmService Web service reference

1. In the Solution Explorer window, right-click your project name and choose Add Web Reference.

2. In the Add Web Reference wizard, type the URL for the CrmService Web service in the URL box, using the name and port number for your Microsoft Dynamics CRM server, and then click Go. For example:

3. http://<servername:port>/mscrmservices/2007/CrmServiceWsdl.aspx

4. When the CrmService Web service is found, change the text in the Web reference name box to CrmSdk and then click Add Reference.

Note that you can name the Web references any name that you like, but for this example they have been named CrmSdk and CrmSdk.Discovery.

Accessing Microsoft Dynamics CRM Web Services

To access the Microsoft Dynamics CRM Web services and work with business entities, your code typically includes these kinds of program statements:

  • Using statements, which provide access to the required namespaces.
  • Code that instantiates the CrmDiscoveryService and CrmService Web service proxies.
  • Instantiation of Microsoft Dynamics types.
  • Invocation of Web service methods.

To include the required .NET namespaces

Add the following lines of code above the namespace statement in your project:

[C#]

 using System.Web.Services.Protocols;
using System.Xml;

To include the required Microsoft Dynamics CRM Web service namespaces

Add the following lines of code after the namespace statement and before the class statement:

// Import the Microsoft Dynamics CRM namespaces.
using CrmSdk;
using CrmSdk.Discovery;
// This class is found in Microsoft.Crm.Sdk.dll. You can add a reference
// to the DLL and remove this class definition if you like.
public sealed class AuthenticationType
{
public const int AD = 0;
public const int Passport = 1;
public const int Spla = 2;
}

This code also adds an AuthenticationType class that is used later in the sample code.

To add configuration information to your solution

Add the following code after the class statement and before the Main method. This code sets up the necessary variables such as organization name. Be sure to fill in the correct values for the server name, TCP port, and organization of your Microsoft Dynamics CRM installation.

[C#]



// The following configuration data is site specific.
// TODO: Set the name and TCP port of the server hosting Microsoft Dynamics CRM.
static private string _hostname = "localhost";
static private string _port = "80";

// TODO: Set the target organization.
static private string _organization = "AdventureWorksCycle";

#endregion Configuration data

// Expired authentication ticket error code. The error codes can be found in the
// SDK documentation at Server Programming Guide\Programming Reference\Error Codes.
static private string ExpiredAuthTicket = "8004A101";





To add error handling to your solution

Add the following code within the Main method. This code will provide some console output you can use to verify that your program is working.

[C#]




try
{
Run();
Console.WriteLine("Authentication was successfull.");
}
catch (System.Exception ex)
{
Console.WriteLine("The application terminated with an error.");
Console.WriteLine(ex.Message);

// Display the details of the inner exception.
if (ex.InnerException != null)
{
Console.WriteLine(ex.InnerException.Message);

SoapException se = ex.InnerException as SoapException;
if (se != null)
Console.WriteLine(se.Detail.InnerText);
}
}
finally
{
Console.WriteLine("Press to exit.");
Console.ReadLine();
}




Your program will not build because the Run method does not exist. You will create this next.

To add the Run method

This method contains all the code needed to use the Discovery service to obtain the correct URL of the CrmService Web service for your organization. The code then sends a WhoAmI request to the service to verify that the user has been successfully authenticated.

Add the following code after the Main method.

[C#]



public static bool Run()
{
try
{
// STEP 1: Instantiate and configure the CrmDiscoveryService Web service.
CrmDiscoveryService discoveryService = new CrmDiscoveryService();
discoveryService.UseDefaultCredentials = true;
discoveryService.Url = String.Format(
"http://{0}:{1}/MSCRMServices/2007/{2}/CrmDiscoveryService.asmx",
_hostname, _port, "AD");

// STEP 2: Retrieve the organization name and endpoint Url from the
// CrmDiscoveryService Web service.
RetrieveOrganizationsRequest orgRequest =
new RetrieveOrganizationsRequest();
RetrieveOrganizationsResponse orgResponse =
(RetrieveOrganizationsResponse)discoveryService.Execute(orgRequest);

OrganizationDetail orgInfo = null;

foreach (OrganizationDetail orgDetail in orgResponse.OrganizationDetails)
{
if (orgDetail.OrganizationName.Equals(_organization))
{
orgInfo = orgDetail;
break;
}
}

if (orgInfo == null)
throw new Exception("The organization name is invalid.");

// STEP 3: Create and configure an instance of the CrmService Web service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = AuthenticationType.AD;
token.OrganizationName = orgInfo.OrganizationName;

CrmService crmService = new CrmService();
crmService.Url = orgInfo.CrmServiceUrl;
crmService.CrmAuthenticationTokenValue = token;
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;

// STEP 4: Invoke CrmService Web service methods.
WhoAmIRequest whoRequest = new WhoAmIRequest();
WhoAmIResponse whoResponse = (WhoAmIResponse)crmService.Execute(whoRequest);

return true;
}

// Handle any Web service exceptions that might be thrown.
catch (SoapException ex)
{
throw new Exception("An error occurred while attempting to authenticate.", ex);
}
}





To add the GetErrorCode method

Add the following code, after the Run method, for the GetErrorCode method that extracts a numeric error code from a SoapException stored in anXmlNode or returns an empty string if no error exists.

[C#]



private static string GetErrorCode(XmlNode errorInfo)
{
XmlNode code = errorInfo.SelectSingleNode("//code");

if (code != null)
return code.InnerText;
else
return "";
}




Now build and run your solution by pressing F5. If you get any compile errors, you can find the complete code sample in the SDK\Walkthroughs\Authentication\CS|VB\ActiveDirectory folder.

  

RetrievePrincipalAccess Message

Retrieves the access that the security principal (user) has for the specified entity instance.


//# The following code example shows how to use the RetrievePrincipalAccess message.

// Set up the CRM service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";

CrmService service = new CrmService();
service.Url = "http://:/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create the SecurityPrincipal object.
// This references the user whose access is being checked.
SecurityPrincipal principal = new SecurityPrincipal();

// Set the properties of th SecurityPrincipal object.
// Type is the typecode of the principalid.
principal.Type = SecurityPrincipalType.User;
// PrincipalId is the GUID of the user whose access is being checked.
principal.PrincipalId = new Guid("F111F0B1-70CE-44B4-8BF2-2E6C7EADA111");

// Create the target for the request.
TargetOwnedAccount owner = new TargetOwnedAccount();

// EntityId is the GUID of the account to which access is being checked.
owner.EntityId = new Guid("2B951FBC-1C56-4430-B23B-20A1349068F3");

// Create the request object.
RetrievePrincipalAccessRequest access = new RetrievePrincipalAccessRequest();

// Set the properties of the request object.
access.Principal = principal;
access.Target = owner;

// Execute the request.
RetrievePrincipalAccessResponse accessResponse = (RetrievePrincipalAccessResponse)service.Execute(access);




CRM 2011 Processes

Processes - Introduction


Processes - Dialogs


Processes - Workflow


Processes - Performance & Versioning

LoseOpportunity Message

Sets the state of an opportunity to Lost.



//# The following code example shows how to use the LoseOpportunity message.
// Set up the CRM service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";

CrmService service = new CrmService();
service.Url = "http://:/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

//Set up the data required for this sample.

// Create an account for the opportunity's potential customer.
account potentialCustomer = new account();
potentialCustomer.name = "Adventure Works Cycle";

Guid createdAccountId = service.Create(potentialCustomer);

// Build a query for US Dollar currency.
QueryByAttribute dollarQuery = new QueryByAttribute();
dollarQuery.EntityName = EntityName.transactioncurrency.ToString();
dollarQuery.Attributes = new string[] { "currencyname" };
dollarQuery.Values = new string[] { "US Dollar" };
// Be aware that using AllColumns may adversely affect
// performance and cause unwanted cascading in subsequent
// updates. A best practice is to retrieve the least amount of
// data required.
dollarQuery.ColumnSet = new AllColumns();

// Create the US currency request.
RetrieveMultipleRequest dollarRequest = new RetrieveMultipleRequest();
dollarRequest.Query = dollarQuery;

// Get US currency to use in the opportunity.
RetrieveMultipleResponse dollarResponse = (RetrieveMultipleResponse)service.Execute(dollarRequest);
transactioncurrency usCurrency = (transactioncurrency)dollarResponse.BusinessEntityCollection.BusinessEntities[0];

// Create an opportunity.
opportunity loseOpportunity = new opportunity();
loseOpportunity.customerid = new Customer();
loseOpportunity.customerid.type = EntityName.account.ToString();
loseOpportunity.customerid.Value = createdAccountId;
loseOpportunity.name = "SDK Sample for LoseOpportunity Message";
loseOpportunity.transactioncurrencyid = new Lookup();
loseOpportunity.transactioncurrencyid.type = EntityName.transactioncurrency.ToString();
loseOpportunity.transactioncurrencyid.Value = usCurrency.transactioncurrencyid.Value;

Guid loseOpportunityId = service.Create(loseOpportunity);

// Create an opportunityclose object.
opportunityclose oppClose = new opportunityclose();

// Set the opportunityclose properties.
oppClose.subject = "SDK Sample for LoseOpportunity Message";

// Set the opportunityid to an existing opportunity.
oppClose.opportunityid = new Lookup();
oppClose.opportunityid.type = EntityName.opportunity.ToString();
oppClose.opportunityid.Value = loseOpportunityId;

// Create the request.
LoseOpportunityRequest loseOppReq = new LoseOpportunityRequest();
loseOppReq.OpportunityClose = oppClose;

// A status of -1 will have the platform set the status to the appropriate value.
loseOppReq.Status = -1;

// Execute the request.
service.Execute(loseOppReq);




ImportCompressedAllXml Message

Import all customizations from an XML file that has been compressed using the WinZip format.



This request requires an ImportExportXml file for import. This example exports this file from CRM and then imports it back into Microsoft Dynamics CRM.
[C#]
// Set up the CRM service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";

CrmService service = new CrmService();
service.Url = "http://:/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create the request.
ExportCompressedAllXmlRequest requestExport = new ExportCompressedAllXmlRequest();
requestExport.EmbeddedFileName = "customizations.xml";

// Execute the request.
ExportCompressedAllXmlResponse responseExport = (ExportCompressedAllXmlResponse)service.Execute(requestExport);

// Get the compressed data
byte[] compressedXML = responseExport.ExportCompressedXml;

// Create the request.
ImportCompressedAllXmlRequest request = new ImportCompressedAllXmlRequest();

// Assign the compressed data
request.CompressedCustomizationXml = compressedXML;

// Execute the request.
ImportCompressedAllXmlResponse response = (ImportCompressedAllXmlResponse)service.Execute(request);




ImportAllXml Message

Import all customizations from an XML file.

 
//# This request requires an ImportExportXml file for import. This example exports this file from CRM and then imports it back into Microsoft Dynamics CRM.

// Set up the CRM service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";

CrmService service = new CrmService();
service.Url = "http://:/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// This is a potentially long running operation. The default 90-second
// time-out might be too short. Set the time-out to be 5 minutes.
// This property takes milliseconds.
service.Timeout = 300 * 1000;

// Create the request.
ExportAllXmlRequest request = new ExportAllXmlRequest();

// Execute the request.
ExportAllXmlResponse exportResponse = (ExportAllXmlResponse)service.Execute((Request)request);

// Create the request.
ImportAllXmlRequest importRequest = new ImportAllXmlRequest();

// Tell the request where the temporary XML file is located.
importRequest.CustomizationXml = exportResponse.ExportXml;

// Execute the import.
ImportAllXmlResponse importResponse = (ImportAllXmlResponse)service.Execute(importRequest);




Understanding Hierarchical Entity Relationships

 

Hierarchical entity relationships require that one of the records have a field to store a unique identifier that references another record. The record that stores the reference to another record is called the child record ( A record in a hierarchical relationship with a parent record where a reference to the parent record is stored in the record. One parent record can be related to many child records. Child records have lookup fields in the form to allow them to be related to a parent record. ) . The record referenced by the unique identifier in the child record is called the parent record ( A record that is in a hierarchical relationship with a child record, where a reference to the record is stored in the child record. One parent record can be related to many child records. ) .

A hierarchical relationship allows each child record ( A record in a hierarchical relationship with a parent record where a reference to the parent record is stored in the record. One parent record can be related to many child records. Child records have lookup fields in the form to allow them to be related to a parent record. ) to store a reference to one parent record ( A record that is in a hierarchical relationship with a child record, where a reference to the record is stored in the child record. One parent record can be related to many child records. ) . A parent record can be referenced by an unlimited number of child records. The parent record can display all the child records in an associated view ( The view of an entity that is displayed in the forms of other entities. The associated view is different from the views that are visible for the entity in its own area of the user interface. For example, in an account record, under Details, you can click Contacts to view and open a contact form. That is the Contacts associated view. There can be only one associated view of each entity. ) .

Issues related to Hierarchical relationships include:

· Defining Relationships

· Data Integrity

· Relationship Behavior

· Limitations for Hierarchical Relationships

· Mapping

Defining Relationships

Relationships are defined between entities. The entity that will represent the child records is called the related entity ( An entity that is associated with a primary entity (record type) through a unique reference defined by using a lookup control on the related entity form. For example, an account has a unique reference to a primary contact. ) . A relationship attribute ( An attribute that exists in a related entity when a hierarchical relationship exists. When added to the form of the related entity, a lookup control is displayed to allow the record to be related to another record as defined in the relationship. ) , also known as a lookup attribute ( An attribute used to create a reference to a related record. Also known as a relationship attribute. ) , is created on the related entity to allow records to store a reference to a parent record. The entity that will represent the parent records is called the primary entity ( The entity that a related entity is associated to. Sometimes called a parent entity. ) in the relationship.

When you create or edit a relationship between entities in Microsoft Dynamics CRM you must start from one of the entities. Which entity is not important because only one relationship will be created and only one relationship needs to be edited. The terminology used depends on whether you start from the primary entity ( The entity that a related entity is associated to. Sometimes called a parent entity. ) or the related entity ( An entity that is associated with a primary entity (record type) through a unique reference defined by using a lookup control on the related entity form. For example, an account has a unique reference to a primary contact. ) .

o A 1:N Relationship is a hierarchical relationship created or viewed from the primary entity. Any one record from the primary entity can be referenced by many records from the related entity.

o A N:1 Relationship is a hierarchical relationship created or viewed from the related entity. Many records from the related entity can reference any one record from the primary entity.

Note: It is important to remember that the same relationship can be viewed from either of the two entities that participate in the relationship.

 

Data Integrity

A hierarchical relationship introduces the opportunity to define rules for data integrity. For example, an opportunity ( A potential revenue-generating event or sale to an account that needs to be tracked through a sales process to completion. ) record has no meaning if it isn't associated with a customer record. Microsoft Dynamics CRM requires that an opportunity record be related to a customer record. However, a task activity ( An action to be performed, such as a task, or a communication item that is sent or received, for example, e-mail, phone calls, and appointments. The status of activities is tracked and the activity history is stored in the system, so users can view the open and closed activities. ) can be meaningful whether it is associated to another record or not. Relating a task activity to another record is optional.

When you create a relationship, you must choose whether to enforce rules for data integrity. If you make the relationship attribute on the related entity a required field by setting a requirement level ( A setting that determines whether users must enter data. For example, when the requirement level of a field is set to Business Required, users will be unable to save the record without entering data in that field. The field will also appear in the Quick Create form. ) of Business Required, you can guarantee that each of the related entity records created through the Microsoft Dynamics CRM application will be related to a record of the parent entity.

Note: Field level constraints only apply to the Microsoft Dynamics CRM application. Records created programmatically through the Microsoft Dynamics CRM Web services are not required to respect field level constraints.

 

Relationship Behavior

Once you create a hierarchical relationship you can control how the relationship behaves to support both data integrity and business rules for your organization. The relationship can control how actions performed on a parent record will cascade down to child records.

You can configure the relationship behavior for the following actions performed on the record of the primary entity:

· Assign ( The related records will be assigned to the same user. )

· Share ( The related entity records will also be shared with the same user or team. )

· Unshare ( The related entity records will no longer be shared with the same user or team. )

· Reparent ( If the owner of the primary entity record changes because the primary entity record was reparented, the owner of any related records will be set to the same owner as the primary entity record. )

· Delete ( The related records can be deleted, unlinked from the primary entity record, or the delete action can be canceled. )

· Merge ( The related records associated with the subordinate record will be reparented to the master record. )

You can choose from three pre-defined and commonly used types of behavior, or you can choose to configure the appropriate cascading action for each action performed on the record of the primary entity.

The three predefined types of behavior are:

· Parental
In a Parental type of behavior, all actions cascade down to the related records. For example, if a parent record is deleted, all child records will also be deleted. If a parent record is reassigned, all the child records are reassigned to the same user.

· Referential
In a Referential type of behavior, none of the actions will cascade down to child records. For example, when a parent record is deleted, the data linking that record in any child records is removed.

· Referential, Restrict Delete
The Referential, Restrict Delete type of behavior is the same as Referential except that the deletion action is not allowed if there are any related records.

You can also choose to define specific cascading behavior for each of the actions by choosing the Configurable Cascading type of behavior. For most actions, your choices are:

· Cascade All
This is the behavior of the Parental type of behavior. All actions will cascade to all child records, including inactive records.

· Cascade Active
Actions will only cascade down to active child records.

· Cascade User-Owned
Actions will only cascade down to child records assigned to the same user as the owner of the parent record.

· Cascade None
This is the behavior of the Referential type of behavior. No actions will cascade.

Data integrity must be preserved when data in records changes or when the status of records change. For example, deleting a parent record breaks the data integrity of any child records if the relationship is required. There are three ways to address this:

· Use the Referential, Restrict Delete type of behavior to prevent the deletion of any records that have dependent child records.

· Use the Parental type of behavior to delete any dependent child records for any parent records that are deleted.

· Use the Configurable Cascading type of behavior and set the Delete action to either Cascade All or Restrict.

If the relationship is not required, it is sufficient to remove the data that establishes the link to the deleted parent record.

In addition to data integrity, your business may have rules that should be applied when data in records changes or when the status of records changes. For example, some organizations may want to reassign all child records when the a parent record is reassigned. The Relationship behavior can cascade this action so it does not need to be done manually.

 

Limitations for Hierarchical Relationships

· Parental Relationships
Each entity can participate in only one parental ( A relationship between entities in which any action taken on a record of the parent entity is also taken on any child entity records that are related to the parent entity record. For example, if you delete a record in the parent entity, the related child entity records are also deleted; or if you share a parent entity record, the related records from the child entity are also shared. ) relationship. Most Microsoft Dynamics CRM  system entities ( Entities that are included in Microsoft Dynamics CRM by default, such as Account. )   already participate in a parental relationship and this relationship cannot be changed.

· Number of Relationships
Enities can have referential relationships with any entity, including system entities. You can create multiple relationships between two entities. Entities can even have referential relationships with themselves - allowing linked records of the same type. However, a record cannot be linked to itself.

· Relationships with Customer Records
Customers in Microsoft Dynamics CRM may be Accounts or Contacts. These two entities together represent a composite Customer ( The account or contact with which a business unit conducts a business transaction. ) entity. Some Microsoft Dynamics CRM system entities, such as Opportunity and Case must be related to a Customer. However, you cannot create this type of relationship with custom entities.

 

Mapping

New child records can be created by users in the associated view ( The view of an entity that is displayed in the forms of other entities. The associated view is different from the views that are visible for the entity in its own area of the user interface. For example, in an account record, under Details, you can click Contacts to view and open a contact form. That is the Contacts associated view. There can be only one associated view of each entity. ) if they click the New button. When this happens, data from the parent record is copied into the form for the new child record. By default, a reference to the parent record is always copied to the relationship lookup field in the child record. You can choose whether data from other fields should be copied at the same time.

Clone Message

Copies an existing contract and its line items.



//# The following code example demonstrates how to clone a contract.
// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";

CrmService service = new CrmService();
service.Url = "http://:/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create the request object.
CloneContractRequest clone = new CloneContractRequest();

// Set the properties of the request object.
clone.ContractId = new Guid("C15AF217-C17E-DA11-B90F-000874DE7397");
clone.IncludeCanceledLines = false;
clone.ReturnDynamicEntities = false;

// Execute the request.
CloneContractResponse cloned = (CloneContractResponse) service.Execute(clone);