405 error – Method not allowed error while calling WCF service inside Plugin in CRM 2011.
Hi,
Recenlty we wrote a plugin that was calling a WCF Rest Service. The plugin was registered on Pre Create of an entity. Here if we were creating the entity record through web interface, the plugin was running fine.
However if we had that plugin being triggered by another plugin (the other plugin was creating the entity record triggering this particular plugin) we were getting “405 – method not allowed” error.
As it turned out the WCF service was getting confused regarding the operation context when being called by another plugin.
Specifying the OperationContextScope fixed the issue.
Original Code
</pre>
using (
var webChannelFactory =
new WebChannelFactory<IAutoNumber>(
new Uri(dictionaryConfigSettings[Constants.AutoNumberServiceUrl])))
{
IAutoNumber referralOffer = webChannelFactory.CreateChannel();
// get the next number from sequence
autoNumber = Constants.PrefixReferralOfferNumber +
AddPadding(
referralOffer.GetNextNumber(Constants.EntityNameReferralOffer),
Constants.PrefixReferralOfferNumberLength);
}
<pre>
The modified code
</pre>
using (
var webChannelFactory =
new WebChannelFactory<IAutoNumber>(
new Uri(dictionaryConfigSettings[Constants.AutoNumberServiceUrl])))
{
IAutoNumber referralOffer = webChannelFactory.CreateChannel();
using (new OperationContextScope((IContextChannel)referralOffer))
{
// get the next number from sequence
autoNumber = Constants.PrefixReferralOfferNumber +
AddPadding(
referralOffer.GetNextNumber(Constants.EntityNameReferralOffer),
Constants.PrefixReferralOfferNumberLength);
}
}
<pre>
The helpful post
http://www.rgoarchitects.com/nblog/CommentView,guid,26d9b30e-c441-4776-9778-4dfdab58bd3d.aspx
Hope it helps.
Filed under: CRM, CRM 2011, Microsoft Dynamics CRM, WCF Tagged: CRM, CRM 2011, Microsoft Dynamics CRM, WCF
This was originally posted here.

Like
Report
*This post is locked for comments