Callout not working?

Lets write a bit more about how to get a callout to work and to make debugging available. I already wrote something about this before in this post: Callout debug: Access is Denied.

So your callout is not fired? Here are some thoughts to get started. Make sure that:

- the callout even should fire. Are you using the right callout? Special attention to the email PreSend and PostDeliver callouts: PreSend is for sending email
and PostDeliver is after you received an email

- you have built your callout in .NET Framework 1.1

- the dll file is placed in the correct directory. By default this would be: "C:\Program Files\Microsoft CRM\Server\bin\assembly"

- you created a callout.config.xml in the same folder. Don't forget the extension xml

- the callout is subscribed correctly in the callout.config.xml. It should look like: http://schemas.microsoft.com/crm/2006/callout/;

A correct example would be: http://schemas.microsoft.com/crm/2006/callout/;

- you reset iis (start, run, iisreset) after placing the new callout files


Okay, now you have checked the basics, then let's continue with the harder things to find out based on an error message. Either from the web interface or the event log (don't forget to check there to see if there is an error)

The error messages I'd like to give some hints on are:

Error (in Web UI):

Could not load type YourCallout from assembly YourCallout, Version=1.0.2512.17524, Culture=neutral, PublicKeyToken=null.
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.


Possible solution:
If your code is written in VB, then make sure that you write the subscription correct. You might think that the class in the subscription should be "YourNamespace.YourCalloutClass", but in fact it should be "YourProjectName.YourNamespace.YourCalloutClass".

Error (from event viewer):
Error: ISV code threw exception: assembly: YourCallout.dll; class: YourNamespace.YourCallout; entity: product, event: postcreate, exception: System.IO.FileLoadException: Access is denied: 'YourCallout.dll'.File name: "YourCallout.dll"


Possible solution: Make sure that the security is set to Full for "Network Service" on your dll files.

Error (from event viewer):
Error: General config file format error: System.Data.SqlClient.SqlException: Could not find stored procedure 'sp_sdidebug'.


Possible solution: After the iisreset first do all the actions that you should do to run the callout and when the callout should have run, then start the debugger on the w3wp process.

Here's another hint for when working with impersonation. When you're using the userContext.UserId to set the callerid value, make sure that you also set the credentials on the webservice as shown below.


service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.CallerIdValue = new CallerId();
service.CallerIdValue.CallerGuid = userContext.UserId;


Error (from event viewer):
Error: ISV code threw exception: assembly: YourCallout.dll; class: Namespace.Callout; entity: account, event: postupdate, exception: wi: Specified cast is not valid.


Possible solution: The file "Microsoft.crm.platform.callout.base.dll" is located in the assembly folder. Remove the file from that folder, perform an IISReset and restart the workflow service.

Error (from event viewer):
Error: ISV code threw exception: assembly: YourCallout.dll; class: Namespace.Callout; entity: account, event: postupdate, exception: System.IO.FileNotFoundException: File or assembly name Microsoft.Crm.Platform.Callout.Base, or one of its dependencies, was not found.


Possible solution: The CRM server is older then the RTM version. Look in the registery (HKLM\software\Microsoft\MSCRM\CRM_Server_Version). The value should be 3.0.5300.0 or above. If it is not, then reinstall the CRM server with the latests bits.

Error (from event viewer):
Precallout event cannot have pre-/post-image subscription. event: preupdate, entity: entityname


Possible solution: This error appears if you are supplying prevalue and postvalue attributes in the callout.config.xml for a precallout. The prevalue and postvalue attributes are only valid for postcallouts. The pre callout does supply all the changed values. If you need more values, then get them via the service.Retrieve method.

No Error info?
If you cannot find any error information and your callout doesn't do anything, then check the registery. There might be a key named "SetupMode" in HKLM\Software\Microsoft\MSCRM\. If it is indeed there, then modify this key to contain the DWORD value "0". After the change, make sure that you perform an "IISReset" (thanks Jevgenij).

Exceptional situation.
There is one situation known in which callouts do not fire. This is when an activity is created by quick campaigns (possibly also regular campaigns). The callout OnCreate will NOT fire for the activities. You'll need to use the CRM 1.2 approach for this situation. Microsoft promised to work on this in the Titan release. If it will be fixed is still a question though.

Well, these were the issues I could think of now. Another approach would be to temporarily remove all complex codes and start with a simple callout that writes something to the eventlog. You then at least know if your callout is fired or not.

Hope this helps you to get your callout working!

32 comments:

Anonymous said...

Thanks for the excellent tips.
We're having a calloutproblem this moment. Our callouts are working on several VPC's.
Now we tried to place them on our production environment and they won't get called in the w3wp.exe.
We used the same callout.config.xml file from the VPC's, but nothing happens. If we use a dll that's just outputting the xmlfile from CRM, than there is no problem.
Eventviewer gives no warnings and no errors are seen in the Tracelogs.

Ronald Lemmen said...

Hi, here are some questions to hopefully get you further.

Have you double tested all the steps as described in the post?

Are you sure that they won't get called? Might it be that the callout just silently fails? Do you have exception handling in your callout?

Are you impersonating the user? Does that user have write access to the location where you're going to place the output file?

I'll add another part to the post regarding impersonating

Hope this helps,

Ronald

Anonymous said...

Thanks for your quick response.
We went through every step multiple times.
In one callout we're working with impersonating, but even with removing this callout, it won't work.
The code has been checked and verified by Microsoft and they had no comments about it.
The thing now is, it's that the dll's are not being added to the w3wp process. So it's in fact normal that we don't see any errors.
Security for the installed user has been set to Full Rights on the assembly folder and the files in it.

Ronald Lemmen said...

If you're sure that the dll isn't being loaded into the w3wp process, then I usually suggest to check and doublecheck the subscription in the callout.config.xml. But you already did that.

A wise German somewhen said 'Ein reboot macht immer gut', but I guess that you also rebooted your machine.

You have had Microsoft to look at your code. Did you open a support request for this? They should help you solve the issue then instead of saying that it looks ok.

Feel free to send me the callout, callout.config.xml and the customizations.xml for the needed entities. I'll try to find some time to look at it so I can extend the article with more solutions. The mail address is: ronaldl at avanade dot com

Anonymous said...

Thanks for the offer Ronald.

Finally we found a solution, apparently there is a registrykey during an installation being set to 1 and after the installation it's being removed.
In our situation, the registry key was not being removed (why? still don't know). By changing the value of it to 0, the callouts started to work.
The regkey is named SetupMode and should be removed or set to 0

I want to thank Benjamin and Arash for their help!

Ronald Lemmen said...

Thanks for the update. I'll add this check to the list of possible solutions.

Anonymous said...

Since i'm new in crm development, and you said that campaign responses (email in my case) will NOT trigger postcreate event, i would be very grateful if you can give me a hint how to workaround this. i'm not familiar with CRM 1.2

Just short explanation: to test callout assembly i'm just adding some text to the log file. works OK on 'contact' entity, but fails on 'email' entity. no error logs.

Atif Faisal said...

do u have any workflow assembly code which can automatically attached a product with invoice?
Regards
faisalfiaz@yahoo.com

Ronald Lemmen said...

Hi faisal,

I dont have such a workflow component available for download. The part in the SDK regarding the workflow assemblies should help you understand and built workflow assemblies.

Kind regards,
Ronald

Anonymous said...

Nice post, Ronald.

I was having the "callout not working" issue and tried every suggestion of there. After several hours of trying every imaginable way to resolve the issue, I've just created the value SetupMode in the registry (it wasn't there) and set it to 0. Guess what... callouts started to work just after the iisreset.
Thought you could add small note about this to your post, so this could save time for someone in future.
P.S. The registry value type is DWORD

Anonymous said...

Nice post Ronald and I have run into just about every possible problem you mentioned at one time or the other. I have a question: It appears that a post callout is not triggered when an email activity is created by using track in crm or setting the regarding when promting an existing email or creating new email and setting the regarding in Outlook. Is this by design? The callout is triggered and works just fine when creating a new email activity or the send email button in crm. Any ideas how to work around this problem.

Ronald Lemmen said...

Hi,

I haven't verified this behaviour, but it can be true because of the same reason as why callouts are not triggered when activities gets created by the quickcampaigns. Microsoft is sometimes not using the crm webservices but accessing the crm API's directly and therefore the callout mechanism isn't being called.

The solution would be to use the crm 1.2 callout chechanism.. Titan should have this solved.

Since i'm not 100% sure if the cause is the same, you can open a case with microsoft. Please let me know the results.

Ronald

Anonymous said...

Hi Ronald

We were told to use the presend and postdeliver events and they seem to work just fine when sending or promoting an email in Outlook. It definately appears that whatever mechanism they are using does not trigger create or update callouts but does trigger presend and postdeliver callout events. Very interesting, thanks for your help

Ronald Lemmen said...

I learn something new every day as well :) Thanks for the update!

Jim Wang said...

Hi Ronald,

After you change the register key (SetupMode), you don't have to do a iisreset or reboot the server, it effects immdediately.

Thanks for your post!

Jim Wang

Ron said...

Just posted a quick followup to this on my blog.

I am working with a client who went live without any rollups on the system. There is a known issue with pre-rollup 1 where if a record is changed by a workflow then the callout is not fired.

We had to work round this because a change in custom status of a record needed to call a web service but we had to work it so that a task was raised to ask the status to be changed by hand. Not pretty but they were only a week from go live when I discovered this.

Anonymous said...

I got this message:

Error: ISV code threw exception: assembly: MyCalloutLibrary.dll; class: MyNamespace.MyCallouts.MyCallout; entity: lead, event: postupdate, exception: System.Security.SecurityException: Requested registry access is not allowed.

My solution was copying and pasting MyCalloutLibrary.dll and callout.config.xml in the same folder (C:\Program Files\Microsoft CRM\Server\bin\assembly), then I deleted MyCalloutLibrary.dll and callout.config.xml and renamed "Copy of MyCalloutLibrary.dll" and "Copy of callout.config.xml" appropiately.

I guess by doing that these new files obtained the right permissions (or who knows, maybe I was just lucky).

godmcse said...

Hello,
I have done everything according to the instructions in "Working with CRM" book to launch a callout.

It does not fire, not trigger. I did what you mentioned in the post. Still nothing.

I am trying to compare a pre and post value of an entity.

any thoughts?
godmcse

godmcse said...

Hello,
I figured out my mistake.

Now I am getting an "ISV event Eror"

System.InvalidOperationException: There is an error in XML document (1, 2). ---> System.InvalidOperationException: "BusinessEntity xmlns='http://schemas.microsoft.com/crm/2006/WebServices'>" was not expected.
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderBusinessEntity.Read232_BusinessEntity()
--- End of inner exception stack trace ---

any thoughts? Please help.

thank you
GODMCSE

godmcse said...

I fixed the priviuos errors. now I am getting this one:

Error: ISV code threw exception: assembly: DataAudits.dll; class: DataAudits.ContactDataAudit; entity: contact, event: postupdate, exception: System.TypeLoadException: Could not load type DataAudits.ContactDataAudit from assembly DataAudits, Version=1.0.2817.17917, Culture=neutral, PublicKeyToken=null.
at System.Reflection.Assembly.GetTypeInternal(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean publicOnly)
at System.Activator.CreateInstanceFrom(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)
at Microsoft.Crm.Callout.CalloutHost.PostUpdate(CalloutUserContext userContext, CalloutEntityContext entityContext)

any thoughts?

Anonymous said...

Hi Ronald,
I try to search in Google for PreSend callout reference, and find your page :).

Hope you can help me. I have used PreSend to reformat email content before it's sent out. It works perfectly for manual activity or send direct email. But, when I use Quick Campaign to send out email, it seems that the callout is not triggered at all.

I have tried to use Workflow, "on create" of "email" entity, then run certain assembly to change the email description. The problem is, this workflow is triggered after the email has been sent, so it's totally useless. I have used Rollup Update 2, and set registry value for "CampaignSendEmail" to 1, so quick campaign email is sent out automatically.

Anonymous said...

Hi Ronald,

I am trying to run the SDK samples for callout and used the calloutsample2 sample for account PreCreate and Postcreate. I have done everything specified in the readme.doc file. But when i create a new account, i get the below error message as pop up box and the account is not created.

File or assembly name Microsoft.Crm.Platform.Callout.Base, or one of its dependencies, was not found.

I looked for this error and found your article for this error, which says that the CRM version could be older than the RTM and in the registry CRM version should be 3.0.5300.0 or later. I have checked the registry and the CRM version is 3.0.5300.0. So this is not the issue in my case. CLuld you please help me to check, why i am getting this error. I have not changed anything in the sample code other than commenting all the functions excluding Precreate and Postcreate.

Any help is appreciated.

Thanks,
Ashwani

Ronald Lemmen said...

Hi Ashwani,

Make sure you check that the file does exist in the GAC (c:\windows\assembly\). If it is not there, then try a repair of CRM.

After backups ofcourse...

Kind regards,

Ronald

Anonymous said...

Hi Ronald,

In my postcallout, i have implememnted impersonation. But at Retrive request, i am still geting Http Status 404:Not found Webexception. I have debuged and checked the code and parameters. all seems to be ok!

Any clue?

Regards,

Ayaz

Ronald Lemmen said...

Hi Ayaz,

Please debug your callout and check the url to which the webservice would like to connect to. Then try this url in Internet Explorer and see if this is correct. Probably it is that url which is incorrect. Otherwise, look for other url's used in your code which could be wrong (think about other webservices etc).

Hope this helps,

Ronald

Unknown said...

When I create a quote from an opportunity, the callout events are NOT triggered. Is this by design? If so, how do I detect this new quote?

I am trying to trap PreCreate or PostCreate callouts of Quote and QuoteDetails entity while I create a quote from opportunity.

If this is not supported then can you please recommond any other approach.

Ronald Lemmen said...

Hi Gunjan,

This is indeed 'by design'. Microsoft has fixed this in CRM 4.0. That could be a solution. Otherwise you'll need to use the CRM 1.2 approach for using callouts. These do get triggered when a record is added to the database. Keep in mind that that callout will not work in CRM 4.0, so if you do migrate to the next version, then you'll need to create a plugin for that specific functionality.

Hope this helps,

Ronald

Craig Alexander said...

You Are Awesome!!! I Have been trying to get call outs working for 2 days now. If only the sdk had mentioned that you need to have the project name in the subscription path.

Unknown said...

Hi Ronald,

Thanks for all your suggestion.

We have util project for all our plugins. We keep getting the foll error "". This is not consistent.

Then we recycle app pools problem will get fixed temproarily.

Because of this we are having tough time in our production environment. We are not able to reproduce in our test env.

Any help in this regard is appreciated.

Thanks & Regards,
Vinoth

Ronald Lemmen said...

Vin, the error description is empty. could you check again and post the error message?

lee said...

I'm working on a CRM 3.0 installation and have create a PreCreate for emails which does it's job nicely when emails are manually created, you mention to use the CRM 1.2 method in reference to a workaround regarding the callouts not firing after being created by a quickcampaign / campaign etc as CRM doesn't use the webservices for these, could you point us in the direction ofhte 1.2 method as i'm struggling to find any reference other than this webpage for it, cheers, Lee

Ronald Lemmen said...

Hi Lee,

The CRM 1.2 approach was by using entries in the database and a com object. You should be able to find the CRM SDK for (Microsoft Business Solutions) CRM 1.2 and look in that for the details.

Though that is the official answer, I can also suggest you the unofficial answer: Look into the possibilities of upgrading your solution to CRM 4 or 2011. Then you'll be able to use the 'child pipeline' for plug-ins which will cover the same issue.

Good luck Lee!

Ronald