Сделал по примеру как в ссылке для ASP:
Код:
using System;
.................................
using Microsoft.Win32;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
public partial class UpdateActivity : System.Web.UI.Page
{
public string orgname;
public string crmurl;
public string metaurl;
protected void Page_Load(object sender, EventArgs e)
{
RegistryKey regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSCRM");
string ServerUrl = regkey.GetValue("ServerUrl").ToString();
crmurl = ServerUrl + "/2007/crmservice.asmx";
metaurl = ServerUrl + "/2007/metadataservice.asmx";
orgname = "Samarasoft";
using (new CrmImpersonator())
{
CrmAuthenticationToken token;
token = CrmAuthenticationToken.ExtractCrmAuthenticationToken(Context, orgname);
token.OrganizationName = orgname;
token.AuthenticationType = 0;
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.CrmAuthenticationTokenValue = token;
service.Url = crmurl;
}
Response.Write("Done");
}
}
Код new CrmImpersonator() вызывает ошибку обращения к несуществующему токену...
Код:
Event code: 3005
Event message: Возникло необработанное исключение.
Event time: 20.10.2008 14:50:28
Event time (UTC): 20.10.2008 9:50:28
Event ID: a22bbfc8755f4f539d4a8ad4786cebed
Event sequence: 47
Event occurrence: 3
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/4/ROOT-8-128689694218393361
Trust level: Full
Application Virtual Path: /
Application Path: C:\inetpub\asp_automate\
Machine name: SRV-CRM-01
Process information:
Process ID: 5768
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE
Exception information:
Exception type: InvalidOperationException
Exception message: OpenThreadToken failed with hr = 1008
Request information:
Request URL: http://crm:1003/UpdateActivity.aspx?sState=Update
Request path: /UpdateActivity.aspx
User host address: 192.168.100.62
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE
Thread information:
Thread ID: 7
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Stack trace: в Microsoft.Crm.Sdk.CrmImpersonator.Impersonate()
в UpdateActivity.Page_Load(Object sender, EventArgs e) в c:\inetpub\Asp_automate\UpdateActivity.aspx.cs:строка 33
в System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
в System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
в System.Web.UI.Control.OnLoad(EventArgs e)
в System.Web.UI.Control.LoadRecursive()
в System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Custom event details: