CrmServiceClient extremely slow when connected to Microsoft Dynamics online / 365 - dynamics-crm

I'm trying to use CrmServiceClient class from the last CRM SDK to retrieve data from a Dynamics 365 environment.
CrmServiceClient caches connection info, even when new instances of CrmServiceClient are created and disposed!. My application connects to different CRMs urls, so I use the flag "RequireNewInstance=true;" in the connection string to avoid caching.
When this flag is used, the performance is terrible (more than 30 seconds to retrieve any data).
Any clues how can I get acceptable performance when accessing different online CRMs?
Here is a simple sample code, but any service call takes a lot of time, not just this:
string connectionString="Url=https://myTest.api.crm.dynamics.com/; Username=myUser#myTest.onmicrosoft.com; Password=myPassword; AuthType=Office365;RequireNewInstance=true;";
using (var client = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString))
{
var orgService = (IOrganizationService)client.OrganizationWebProxyClient ?? client.OrganizationServiceProxy;
var response = (RetrieveVersionResponse)orgService.Execute(new RetrieveVersionRequest());
}
Note: I used to use the CrmConnection class from previous SDKs, this had much better response times but now this cannot be used to access CRM online (v 8.1.1 or above)

Related

Online Dynamics CRM 2015 web service call error IdentityProvider cannot be null

I've just started on CRM and ran into some trouble with calling the Organization service.
I've read that for online CRM that I need to get the device ID and password and pass that in the method. This is done by calling the HelperCode in the SDK "DeviceIdManager".
All I wanted to do was simply connect to the service and then I'd do what I needed to do (e.g. retrieve account information).
To keep it simple I did (not real username and password):
Uri orgUri = new Uri("https://xxx.api.crm.dynamics.com/XRMServices/2011/Organization.svc");
ClientCredentials cc = new ClientCredentials();
cc.UserName.UserName = "abc123#xxx.onmicrosoft.com";
cc.UserName.Password = "abc123";
//GetDeviceCredentials is from the SDK helper class
OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(orgUri, null, cc, GetDeviceCredentials());
orgProxy.Authenticate();
This is the error on the Authenticate():
I searched around and it seems that I've followed the general idea of what others have done.
Any suggestions on how I can get it to authenticate properly so i can query the account entity would be great.
I've done something similar using the Discover Service and that works (without the Device Credentials) so I'm a bit perplexed of what I've done wrong here.
Thanks for your time.
I feel like a brick.
I should have paid more attention to the MSDN.
The call should have been "LoadOrRegisterDevice" instead of GetDeviceCredentials.

Acessing Microsoft CRM Online using Office 365 authentication

yesterday I created a new installation of Microsoft CRM Online.
Now I'm trying to access the webservice using the sdk provided from Microsoft.
When i try to connect to Microsoft CRM Online I get this error:
An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.
I read in some posts that it can be the hours difference between my machine and the CRM Online Server, but I've tried running this code unsuccessfully using all the hours.
CrmConnection crmConnection = CrmConnection.Parse("Url=https://desenvolvimento.crm2.dynamics.com/XRMServices/2011/Organization.svc; Username=jones.rives#desenvolvimento.onmicrosoft.com; Password=XXX;");
OrganizationService service = new OrganizationService(crmConnection);
Entity account = new Entity("account");
account["name"] = "Test Account";
account.Id = Guid.NewGuid();
Guid accountId = service.Create(account);
Is it different to connect to CRM Online using 365 credentials? I really can't find the problem, and I've tried many solutions, but none worked.
Thanks in advise.
You don't need to put the endpoint inside the connection string when you use the simplified connection, just the organization url.
Assuming your url is correct (meaning you can login using a browser), try with:
CrmConnection crmConnection = CrmConnection.Parse("Url=https://desenvolvimento.crm2.dynamics.com; Username=jones.rives#desenvolvimento.onmicrosoft.com; Password=XXX;");
OrganizationService service = new OrganizationService(crmConnection);
Entity account = new Entity("account");
account["name"] = "Test Account";
Guid accountId = service.Create(account);

How to understand Namespace of outlook 2007 data store

Firstly , I am a freshmen to outlook add-in development,Recently I read some learning material from MSDN or other tutorial, The First thing makes me confused is if I want to find something like a certain Appointment or Meeting Request from inbox, I should firstly use Application.GetNameSpace(“MAPI”) to get a NameSpace instead of getting some kind of object like Folder or Appointment Collections and so on.
I don't understand the Data Store Access pattern of Outlook 2007 in Add-in development. I hope someone can help me better understand Data store access of outlook 2007.
A MAPI Session is required to interact with an Outlook Data Store. Application.Session is interchangeable with Application.GetNamespace("MAPI"). You can think of a session as a connection to the Outlook Data Store.
To retrieve appointments, you can use Namespace.GetDefaultFolder.
Outlook.Folder appointmentStore = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder;
string apptSubject = string.Empty;
foreach (Outlook.AppointmentItem appt in appointments.Items.OfType<Outlook.AppointmentItem>())
apptSubject = appt.Subject;

Using EWS API to search through different users mailboxes

We are developing a module with the main goal being to track and collect information about damage inspections (insurance market). Each case has a code (e.g. L000525). Each case could be managed by several people. All the emails related to a specific case include the case code in the subject.
What we want to do is to collect and show the incoming and sent emails related to each specific case.
The idea is that any user can open a "Case management" window, select an specific case, and then get all the related information (including the emails of course).
We have to find the emails into the the mailboxes of around 20 users. So the questions are:
Which is the better way to do this? Will it consume a lot of time and resources?
We are new in the Exchange world so we are thinking Exchange impersonation, but we are not sure at all. The module is developed in Silverlight 3, WCF, SQL Server + Exchange 2007.
If the credentials used to connect to EWS have rights to access a user's mailbox then you should be able to do something like this:
var service = new ExchangeService();
service.Credentials = new WebCredentials("user_with_access#example.com", "password");
service.AutodiscoverUrl("a_valid_user#example.com");
var userMailbox = new Mailbox("target_user#example.com");
var folderId = new FolderId(WellKnownFolderName.Inbox, userMailbox);
var itemView = new ItemView(20); // page size
var userItems = service.FindItems(folderId, itemView);
foreach (var item in userItems)
{
// do something with item (nb: it might not be a message)
}
That's it. Wow, my first SO answer!
A full working example of what #smcintosh has done above is here: Office365 API - Admin accessing another users/room's calendar events. It is a full java class that should compile and run and accesses a room resource calendar. Good luck!

Send outlook appointment through asp.net error HRESULT: 0x80004004

I am trying to send an outlook appointment through code. My code is posted below. When I run it on the server with IIS 6 and an app pool under a domain account identity, it throws this error. I have tried changing various settings on the server and none worked. Outlook 2007 is installed. I have even made the domain account a local admin. Please help!
Description: An unhandled exception
occurred during the execution of the
current web request. Please review the
stack trace for more information about
the error and where it originated in
the code.
Exception Details:
System.Runtime.InteropServices.COMException:
Operation aborted (Exception from
HRESULT: 0x80004004 (E_ABORT))
Line 201: objAppt.Send();
Code below:
Microsoft.Office.Interop.Outlook.Application objOL
= new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.AppointmentItem objAppt
= (Microsoft.Office.Interop.Outlook.AppointmentItem)objOL
.CreateItem
(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
objAppt.Start = startTime;//datetime
objAppt.End = endTime;//datetime
objAppt.Subject = subject;
objAppt.Body = body;
objAppt.Location = location;
objAppt.MeetingStatus
= Microsoft.Office.Interop.Outlook.OlMeetingStatus.olMeeting;
objAppt.RequiredAttendees = "test#test.com";
objAppt.Send();
objAppt = null;
objOL = null;
Yes as casperOne said I wouldn't use outlook on the server. I would use CDO or RDO(redemeption) for this. or even use vcal and send the vcal on a system.Net.Mail.
Update:
Take a look at http://www.dimastr.com/redemption/rdo/RDOAppointmenItem.htm
Show you how to do excatly what you want to do using RDO. You can do the same with CDO as well. Check out CDOLive.com
You will have to construct a teh login details as you are on a server that has no Outlook profile (thats if you remove the one that you allready have on there)
Quite simply, you shouldn't be doing this. It is not recommended that you run Office in a server environment because of the threading (and desktop session) requirements that Office has.
Are you trying to do this on an Exchange server? If so, then I would interact directly with the Exchange server (using WebDAV perhaps?).
If not connecting with Exchange, then take a look at the headers for an invitation to the event. The invitations should be nothing more than regular emails with custom header information.
I guess the reason you cannot use Outlook from an IIS application is because the current user the IIS app is running under does not have an Outlook profile associated.
Therefore you can instantiate Outlook objects and set their properties, until profile-specific functionality is required, such as the Send() command, which would store the outgoing mail in the user's/profile's (non-existing) pst file.
Don't do this using Outlook automation.
Straight from the horse's mouth:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.
http://support.microsoft.com/kb/257757
Examine email headers sent by Outlook when it's doing this job to work out how this is done, and emulate it using the standard .NET SmtpClient stuff.

Resources