1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
CrmDiscoveryService discoveryService = new CrmDiscoveryService();
discoveryService.UseDefaultCredentials = true;
discoveryService.Url = "http://srv/MSCRMServices/2007/AD/CrmDiscoveryService.asmx";
// Retrieve the list of organizations that the logged on user belongs to.
RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
RetrieveOrganizationsResponse orgResponse =
(RetrieveOrganizationsResponse)discoveryService.Execute(orgRequest);
// Locate the target organization in the list.
OrganizationDetail orgInfo = null;
foreach (OrganizationDetail orgDetail in orgResponse.OrganizationDetails)
{
if (orgDetail.OrganizationName.Equals("dev"))
{
orgInfo = orgDetail;
break;
}
}
// Check whether a matching organization was not found.
if (orgInfo == null)
throw new Exception("The specified organization was not found.");
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = orgInfo.OrganizationName;
CrmService crmService = new CrmService();
crmService.Url = orgInfo.CrmServiceUrl;
crmService.CrmAuthenticationTokenValue = token;
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
try
{
contact webContact = new contact();
webContact.lastname = "essai";
webContact.salutation = "1";
//webContact.telephone1 = telephone.Text.ToString();
// Creates the lead in Crm
TargetCreateContact target = new TargetCreateContact();
// Set the properties of the target object.'
target.Contact = webContact;
// Create the request object.
CreateRequest create = new CreateRequest();
// Set the properties of the request object.'
create.Target = target;
// Execute the request.
//CreateResponse created = (CreateResponse)service.Execute(create);
Guid contactid = crmService.Create(webContact);
//string stcontact = created.id.ToString();
// Call the Create method to create an account.
}
catch (Exception pb)
{
} |
Partager