CRM 2011 Online 環境に接続しようとしています。「コンソール アプリケーション」経由で接続できますが、「ASP.net」アプリケーション経由で同じコードを使用して接続しようとすると、機能せず、「認証エラー」が表示されます。エラー ({"保護されていない、または正しく保護されていない障害が相手から受信されました。障害コードと詳細については、内部の FaultException を参照してください。"})。
「ASP.net」環境で動作させるために何か特別なことをする必要がありますか? インターネットで見つけたいくつかのソリューションをテストしましたが、すべて同じエラーが発生します。
私の簡略化されたコードの「コード」スニペット:
private static ClientCredentials GetDeviceCredentials()
{
return Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();
}
protected void Button1_Click(object sender, EventArgs e)
{
//Authenticate using credentials of the logged in user;
string UserName = "*****"; //your Windows Live ID
string Password = "*****"; // your password
ClientCredentials Credentials = new ClientCredentials();
Credentials.UserName.UserName = UserName;
Credentials.UserName.Password = Password;
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
//This URL needs to be updated to match the servername and Organization for the environment.
Uri OrganizationUri = new Uri("https://*****.crm4.dynamics.com/XRMServices/2011/Organization.svc"); //this URL could copy from Setting --> Developer Source
Uri HomeRealmUri = null;
//OrganizationServiceProxy serviceProxy;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, GetDeviceCredentials()))
{
IOrganizationService service = (IOrganizationService)serviceProxy;
OrganizationServiceContext orgContext = new OrganizationServiceContext(service);
var theAccounts = orgContext.CreateQuery<Account>().Take(1).ToList();
Response.Write(theAccounts.First().Name);
}
}
「LiveDeviceID」フォルダの内容を削除したり、デバイス登録ツールを再実行したりするなど、いくつかのことを試しました。しかし、「コンソールアプリケーション」では機能するが、「asp.net」ソリューションでは機能しないのは奇妙です...
PS : crmsvcutil.exe /url: https://org.crm4.dynamics.com/XRMServices/2011/Organization.svc /o:crm.cs /u:username /経由で「コンテキスト」ファイルを生成できます。p:パスワード /di:デバイスユーザー名 /dp:devicPWD