Показать сообщение отдельно
Старый 15.02.2010, 10:40   #1  
moskalevas is offline
moskalevas
Участник
 
107 / 11 (1) +
Регистрация: 16.07.2009
Создание карточки через консольное приложение
Добрый день!
Пытаюсь создать консольное приложение.При его запуске должна создаваться карточка ПРЕДЛОЖЕНИЯ с заполненными обязательными полями.
Написал небольшой код.Выдаётся ошибка: The request failed with HTTP status 401: Unauthorized.
Подскажите в чём может быть ошибка.

static void Main(string[] args)
{
// Create and configure the CrmDiscoveryService Web service proxy.
CrmDiscoveryService discoveryService = new CrmDiscoveryService();
discoveryService.UseDefaultCredentials = true;
discoveryService.Url = "http://[адр_серв]/MSCRMServices/2007/AD/CrmDiscoveryService.asmx";
// Retrieve the list of organizations that the logged on user belongs to.
RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
//orgRequest.UserId = args[0];
//orgRequest.Password = args[1];
RetrieveOrganizationsResponse orgResponse = (RetrieveOrganizationsResponse)discoveryService.Execute(orgRequest);
// Locate the target organization in the list and Decalre the Security Token to Access CrmService.
CrmService service = new CrmService();
CrmAuthenticationToken token = new CrmAuthenticationToken();
foreach (OrganizationDetail orgDetail in orgResponse.OrganizationDetails) // It is only One organization in our case ..
{
Console.WriteLine("*Organization : " + orgDetail.OrganizationName);
token.OrganizationName = orgDetail.OrganizationName;
Console.WriteLine("*Organization Url : " + orgDetail.CrmServiceUrl);
service.Url = orgDetail.CrmServiceUrl;
}

string name_ = "qweasd";
//код пересмотра
CrmNumber numrevision = null;
numrevision = new CrmNumber();
numrevision.Value = 0;

//Прайс-лист
Lookup lookuppricelevelid = null;
Guid pricelevelGuid = new Guid("721DDFBF-E26A-DE11-A2A2-000E0C4BF7BF");
lookuppricelevelid = new Lookup();
lookuppricelevelid.Value = pricelevelGuid;

//Валюта
Lookup lookuptransactioncurrencyid = null;
Guid currencyGuid = new Guid("8E3C79F6-4F2B-DE11-A2A2-000E0C4BF7BF");
lookuptransactioncurrencyid = new Lookup();
lookuptransactioncurrencyid.Value = currencyGuid;

//Потенциальный клиент
Customer customcustomerid = null;
Guid customerGuid = new Guid("2C4030BD-E496-DE11-9267-000E0C4BF7BF");
customcustomerid = new Customer();
customcustomerid.Value = customerGuid;

Owner ownerid1 = null;
Guid ownerGuid = new Guid("D5E8C2FD-7A6F-DE11-9267-000E0C4BF7BF");
ownerid1 = new Owner();
ownerid1.Value = ownerGuid;

quote quoteCRM = new quote()
{

//quotenumber = quote.QuoteNumber,
ownerid = ownerid1,
name = name_,
customerid = customcustomerid,
pricelevelid = lookuppricelevelid,
revisionnumber = numrevision,
transactioncurrencyid = lookuptransactioncurrencyid

};

Guid quoteguid = service.Create(quoteCRM);

}