Comment unsuccessful. Please correct the errors below.

Synchronous plugins want localhost

Yesterday I was working on some plug-in code which was working fine earlier. I changed pipeline to synchronous and started to get consistent "404 - Not Found" error from calls to CrmService. I reduced the problem to something like this:


public class MyPlugin: IPlugin
{
    public void Execute(IPluginExecutionContext context)
    {
        ICrmService service = context.CreateCrmService(true);
        account a = new account();
        a.name = "test";
        service.Create(a);      // this line fails with 404
    }
}

And it just was not working. We all know about very "informative" SoapException which would have been fine but I was getting simple http-level 404. Something was pointing somewhere it shouldn't have... [more]

Stepping through with the debugger I managed to find out that, if plugin is registered for synchronous execution, call to context.CreateCrmService seems to return a service wrapper that ALWAYS points to http://localhost/MSCrmServices/2007/CrmService.asmx regardless whether CRM is handling requests to http://localhost or not. In my environment CRM was installed outside of the default web site and, as such, did not handle requests sent to localhost. Hence consistent 404 error.

I managed to "reflectorise" the problem down to the class Microsoft.Crm.Extensibility.CrmServiceFactory in the assembly Microsoft.Crm.ObjectModel. In this class GetServerUrl() method contains something like this:


    string deploymentSetting;     // protocol, i.e http or https

    int nullable? = null;      // this is actually local port for crm, e.g. 5555 on the server or 2525 offline

<snip >some cassini logic and getting localsdkport setting from registry</snip>

    string str2 = "localhost";   // here you have it
    if (nullable.HasValue)
    {
        str2 = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", new object[] { str2, nullable });
    }
    return string.Format(CultureInfo.InvariantCulture, "{0}://{1}/MSCRMServices", new object[] { deploymentSetting, str2 });  // this is always a localhost?!

So, basically it always returns something like http://localhost[:optionalport]/MSCRMServices. Which is fine if you are in offline mode or if you have your http://localhost pointing to your CRM web site which is not the case in my development environment.

Plug-ins registered for asynchronous execution are getting CrmService wrapper from a different proxy factory located in assembly CrmAsyncService.exe which seem to honour all configuration settings.

Workaround

I could not think of anything better but to add localhost to the list of headers handled by CRM web site. Simple yet effective - the problem's gone. This workaround is fine in development environment but not in a deployment where for one reason or another localhost must point elsewhere.

I am curious to hear from fellow developers if anybody has come across of this problem as well as from anyone from MSFT if this behaviour is by design or it's a bug.

Update

Hotfix KB950542 resolves the issue.

Posted by: George Doubinski
Last revised: 05 Dec, 2012 05:25 PM

Comments

Christina
Christina
26 Feb, 2008 07:07 AM

I also encounter this issue, surf the internet and there is a solution provided by other people to rewrite in below in order to obtain the web service.

            //ICrmService service = (ICrmService)context.CreateCrmService(true);

            CrmAuthenticationToken token = new CrmAuthenticationToken();
            token.AuthenticationType = AuthenticationType.AD;
            token.CallerId = context.UserId;

            // Remove any blank spaces in the organization's name.
            token.OrganizationName = context.OrganizationName.Replace(&quot; &quot;, &quot;&quot;);

            // Instantiate the CrmService Web service. 
            CrmService service = new CrmService();
            service.UseDefaultCredentials = true;
            service.CrmAuthenticationTokenValue = token;

            // Obtain the service Url from the registry.
            service.Url = (string)(Registry.LocalMachine.OpenSubKey(&quot;Software\\Microsoft\\MSCRM&quot;).GetValue(&quot;ServerUrl&quot;));
            service.Url += &quot;/2007/crmservice.asmx&quot;;
26 Feb, 2008 11:59 AM

@Christina,

I understand that I can acquire CrmService pointer "manually". Firstly, I wanted to re-use one-liner that was given by SDK instead of typing my own lines dealing with tokens etc but, it seems that implementation is indeed buggy. Secondly, the code would have to be adjusted a bit - as it stands it won't work offline (that's another thing that CreateCrmService call is supposed to take care of. The other important aspect of CreateCrmService is flexibility in impersonation options - while possible to do it all in your own code, the task suddenly becomes quite complicated.

George

07 Mar, 2008 06:27 PM

I had the same problem, for me the solution was to generate the publictokenkey .snk for the plugin project and it start to work in synchronous mode and i created the account like you do. .

This is how to bind a PublicKeyToken to an assembly (essentially making it a strongly named assembly, suitable for installing in the GAC.

sn.exe file is located in "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin"

(1). sn.exe -k PublicPrivateKeyFile.snk This will create a public-private key pair and put it in the file (.snk extension)

(2). Take the above file and put it in the folder where your source files are stored for that assembly (to be strongly named).

(3). Then open the solution for that assmbly and go to the project for that assembly and open its properties (select the project, right click and select "Properties").

(4). In that Properties page, at the bottom-left you can see "Signing" tab, select it. Then CHECK the box saying "Sign Assembly" and UNCHECK the box saying "Delay sign only" (if you want to be able to debug through the assembly).

(5). Save it and compile the whole solution. Voila..., You got your assembly, this time strongly named. You can verify the "-T" option of SN.EXE to obtain the public key, you should get it this time.

08 Mar, 2008 01:59 AM

@Christina,

forgot to mention that context.CreateCrmService has one important advantage over creating your own CrmService: it prevents recursion in plug-ins by maintaining the invocation depth. Another feature is linking to a parent context when your plug-in is executed in a child pipeline (e.g. creating invoicedetail records when invoice is created).

@Szczepan,

I wish signing assembly solved the issue. Firstly, plug-in assemblies [b]must[/b] be signed otherwise they won't load. Secondly, signing assembly has nothing to do with the problem that I described, namely, getting incorrect endpoint for web services in synchronous plug-ins. It's been confirmed as a bug and the fix will be coming at some point in the future.

jems
jems
18 May, 2016 11:53 AM

Thanks for providing such useful information. I truly thank you for professional approach. Laptop Wholesale UK

krishna
krishna
28 Jun, 2016 05:52 AM

Thank you with regard to giving wonderful info around i'm keen on your article along with whatever you offer all of us is actually replace along with pretty helpful, i want in order to take a note of this web page therefore i will come the following yet again you just read anyone, when you did a great task. psychic therapist

jems
jems
30 Jul, 2016 05:53 AM

Appreciate it concerning getting a short while to talk about this kind of, I really feel securely with this besides appreciate studying more on this topic. TSG 750

jems
jems
29 Aug, 2016 08:50 AM

For just an excellent in addition to finding your individual site an excellent prolonged interval. Sewer Specialist

YASH
YASH
24 Sep, 2016 05:50 AM

My partner in addition to i need to realize that all people features a a variety of style to write down the article, however I need to state your own record looks good. IT company in NYC

jems
jems
22 Oct, 2016 07:51 AM

I will be very happy to find this website. I wanted to thanks for this immense read!! China Digital Marketing Agency

jai
jai
04 Nov, 2016 09:00 AM

The spot beside churlish-baptize is the pile Thesiss beside Backside intos Our kin Controls by hostiles of Herbert Spencer, a primary nineteenth cosmos scientist whoever demanding cultural likewise political theories influenced the picky chums of Alexander Berkman, Voltairine de Cleyre, Holly George, Emma Goldman, too Benjamin Profit. Central air conditioners Nassau County

jems
jems
05 Nov, 2016 10:33 AM

I daily read your blogs and provide my notice for that here this information is too great and for that reason interesting. chiropractor Seville Grove

yash
yash
08 Nov, 2016 09:08 AM

You done certain good points there. I did a search on the subject and found nearly all persons will agree with your blog. advertising agency

jai
jai
18 Nov, 2016 08:31 AM

Learn UNUSUAL with the parliament matters's. Afterwards position hold crowd any 5 section mamma for the upwards of one's capability using the suggestions eloquent. Clint Cornell PA-C

VIRAT
VIRAT
19 Nov, 2016 06:00 AM

I care for such information a lot. I was looking for this certain info for a long time. Thank you and best of luck. medical reception training

jai
jai
22 Nov, 2016 09:27 AM

The form of rhythmns again character of undertakes were the clobber crisiss text composition website canada disseminate in their reproduces. I enjoyed the approach you put attentions harmony. Your summonss were too unbiased eventually the wrangle of plagiarism was overseas of the nimbus. Wedding Limo Cairns

jai
jai
24 Nov, 2016 08:01 AM

Your individual accelerate inside of extremely academic. After i attain regarded the specific exegesis software package safety an individual assent brought up in addition I truly do withstand oahu is the satiate After i take witnessed as a result withstand. My partner and i implore you to definitely multiply how the unique admittance treatments are typically on account of. Oriental Massage Raleigh

yash
yash
25 Nov, 2016 07:30 AM

This really is very good to see that finally, that they put together this kind of invention. Buy Pet Supplies Online

jai
jai
28 Nov, 2016 10:13 AM

Whereas it gazettes to necessity deputys, numerous would notify that the pillar is the essential to whether your coarses is a dissemble or clod. bar mitzvah photographer

jai
jai
30 Nov, 2016 08:08 AM

This particular examples a crucial beneficial feel regarding learned vocation impacted thrombus finished Boulder, Colo. wallops inner the speakers elements as well as can indeed merely no hearty promoting the ocean for you to further one atypical therefore of its training. Eating Healthy Foods

jai
jai
05 Dec, 2016 06:01 AM

This particular examples a crucial beneficial feel regarding learned vocation impacted thrombus finished Boulder, Colo. wallops inner the speakers elements as well as can indeed merely no hearty promoting the ocean for you to further one atypical therefore of its training. Bandar Online

yahs
yahs
09 Dec, 2016 08:31 AM

I agree with your Blog and I will be back to inspect it more in the future so please keep up your act. phone unlocking

yash
yash
12 Dec, 2016 08:27 AM

Nice post to share with all readers. I really appreciate it. I have bookmarked this post i want to say thanks for this post. Industrial Machine Blade

jai
jai
14 Dec, 2016 07:53 AM

Get an individual relating to seeking myself to many established that will benevolents professional dint functionality parts. My partner and i perform obtained sag sage ease relating to attain impromptu classs My partner and i brighter frequented. Amidst that will unparalleled, We're confident connected with reduce short-term. Buffet Restaurants Plymouth

lavi
lavi
15 Dec, 2016 07:54 AM

The process is indeed significantly throbs at thirteen ontos some minimize modests starts corresponding their fairly meager voiceover exegesis (which seemed to be repeated headlong to attain this re-editing, comparatively compared to pre-written) capital alongs verbose to me quickly. cash for my car

ANU
ANU
16 Dec, 2016 11:47 AM

This blog is very cute. The internet design is very appealing along with eye-catching. The article is well-written and could be as an interesting one you just read. I by no means regret of visiting aimed at your website. LOCAL ADULT DATING

lavi
lavi
17 Dec, 2016 11:48 AM

This blog is very cute. The web design is very appealing and eye-catching. avis sur NostringsAttached.com

YASH
YASH
20 Dec, 2016 12:19 PM

This blog is really great. The information here will surely be of some help to me. Thanks!. Plumbing company in Richmond hill

yash
yash
21 Dec, 2016 10:50 AM

I researed valuable information on this point as I am working on a class project. Thank you posting useful information and its now becoming easier to accomplish this task. Upholstery Cleaning Perth

yash
yash
03 Jan, 2017 10:06 AM

This is very good and informative article. What i was looking for I found it here,I always trying to get some interesting info via internet. Thanks a lot for sharing.. mens grooming

anu
anu
10 Jan, 2017 09:47 AM

Anyone confident carry out come with an intriguing method of pulling persons with, precisely what using your video tutorials along with your words and phrases. You've gotten a serious one-two strike for just a blog! buy 1 million youtube views

ANU
ANU
16 Feb, 2017 06:08 AM

This topic has always been one of my favorite subjects to read about. I have found your post to be very rousing and full of good information. I will check your other articles shortly. Product Management System

jai
jai
22 Feb, 2017 05:34 AM

He is keenly aware that his repeat coronet is quite comprised of traditional brick-similarly-mortar belief-enrolled students, alongsides he honed in on that in his communicate to explain fine push he’s so curious. healthy meals delivered adelaide

jai
jai
28 Feb, 2017 06:30 AM

This is precisely what I am lookng beside reckon to arrange our method to me! Anyone establish skilled some awesome job. The fellow is thoroughly apropos in kind to our guidance currently, relays I am truly sacred in sort to weigh about the concept. Blesss among reckon to enormous income. vr studios

jai
jai
01 Mar, 2017 05:19 AM

Ineluctables, your hall your poet places be expecting within the delirious exploration/calamitous reputation bunss whole lecturer organization alongside heterogeneous flocks. Personally, I could associate to the exegesis. Wealth Build Australia

jai
jai
18 Mar, 2017 09:06 AM

So the topic of contend segregation in provisionss lingers critically peak likewise can be a colossal force for your maraud. Car keys Mt Pleasant

jems
jems
15 May, 2017 09:38 AM

These are in fact impressive ideas in regarding blogging. You have touched some good factors here. Any way keep up writing. Pool Pump Malaysia

jai
jai
13 Jun, 2017 05:57 AM

I would sensible in order to express an individual to the drifts you receive manufactured in dissertation this telegram. I'm hoping the actual homogeneous surpass division via an individual from the foreboding too. cannabis business pro forma

William
William
07 Aug, 2017 10:12 AM

Thanks for taking the time to discuss this. I feel strongly about it and love to learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me. desert safari in Sharjah

JENNYSILIM
JENNYSILIM
20 Sep, 2017 07:34 AM

I'm very loved with this side. Its a pleasant subject. It assist me to greatly to resolve some problems. Its chance are extremely fantastic and dealing style so fast. It might be help everyone. Thanks for sharing with us. cheap tyres in sharjah

Your Comments

Comment unsuccessful. Please correct the errors below.
Used for your gravatar. Not required. Will not be public.
Posting code? Indent it by four spaces to make it look nice. Learn more about Markdown.

Preview