从 MS CRM 事件发出 AJAX 请求
我需要从 MS CRM Dynamics 4.0 中表单的 onSave 事件向某些脚本发出 AJAX 请求。 我现在拥有的代码是
var http_request;
// Prepare the xmlHttpObject and send the request.
try{
http_request = new ActiveXObject("Msxm12.XMLHTTP");
}catch(e){
try{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
alert("Something went wrong..");
}
}
var poststr = "foo=bar";
http_request.open("POST", "/folder/index.html", false);
http_request.setRequestHeader("Content-Type","text/xml; charset=utf-8");
http_request.send(escape(poststr));
// Capture the result.
var resultXml = http_request.responseText;
alert(resultXml);
警报现在为我提供了 404 类型错误的内容。我确信该页面就在那里,可以通过浏览器访问。
如果我改变
http_request.open("POST", "/folder/index.html", false);
到
http_request.open("POST", "localhost:5555/folder/index.html", false);
open() 失败,显示“权限被拒绝”。
更新(2009 年 12 月 7 日);
我在 CRM 的 ISV 文件夹中创建了一个虚拟目录,并上传了一个 ASP.NET 应用程序。现在,如果我转到 crm.url.nl:5555/ISV/Default.aspx 我得到;
“Microsoft.Crm.WebServices.Crm2007.CookieAndSoapHeaderAuthenticationProvider、Microsoft.Crm.WebServices、版本=4.0.0.0、文化=中性、PublicKeyToken=31bf3856ad364e35”不存在。 参数名称:Microsoft.Crm.WebServices.Crm2007.CookieAndSoapHeaderAuthenticationProvider、Microsoft.Crm.WebServices、Version=4.0.0.0、Culture=neutral、PublicKeyToken=31bf3856ad364e35
带堆栈跟踪;
[ArgumentException: 'Microsoft.Crm.WebServices.Crm2007.CookieAndSoapHeaderAuthenticationProvider, Microsoft.Crm.WebServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' doesn't exist.
Parameter name: Microsoft.Crm.WebServices.Crm2007.CookieAndSoapHeaderAuthenticationProvider, Microsoft.Crm.WebServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]
Microsoft.Crm.Authentication.BaseAuthenticationSettings.CreateType(String typeName, Type requiredBaseType) +265
Microsoft.Crm.Authentication.BaseAuthenticationSettings.CreateProvider(String typeName, IDictionary`2 configuration) +28
Microsoft.Crm.Authentication.AuthenticationPipelineSettings.LoadPipeline() +262
Microsoft.Crm.Authentication.AuthenticationPipelineSettings.get_AuthenticationProvider() +16
Microsoft.Crm.Authentication.AuthenticationEngine.Execute(Object sender, EventArgs e) +524
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
有人知道吗? .NET 应用程序只向 Response 写入一个单词,因此没有什么特别的......
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我知道这个想法是什么了。
如果您想从 CRM 4.0 对动态 .NET 应用程序进行 AJAX 调用,请执行以下操作。
将 .NET 应用程序的程序集放入 CRM 文件夹中的 CRMWeb/bin 文件夹中。将您的 aspx 文件放在 ISV 文件夹中的一个文件夹中。我使用了 stunnware.com 文件夹,因为它就在那里,但为了整洁起见,您可能需要创建另一个文件夹。
然后,在 onSave (或任何 on-event)中放置类似这样的内容;
当然,如果您希望 CRM 对 xml 请求的响应执行任何操作,您可以使用 onreadystatechange 来实现。
希望这可以帮助其他人。这看起来似乎很简单,但我花了很长时间才弄清楚如何做到这一点(尽管我知道如何使用 AJAX 和 .NET 之类的东西)。我认为 CRM 开发人员被微软冷落是一种耻辱。他们真的应该花更多的时间来记录 SDK 以及如何做这样的事情。
Okay, I found out what the idea is.
If you want to do an AJAX call to a dynamic .NET application from CRM 4.0, here's what you do.
Put the assemblies of your .NET application in the CRMWeb/bin folder in the CRM folder. Put you aspx files in a folder in the ISV folder. I used the stunnware.com folder, because it was there, but you may want to create another folder for the sake of tidyness.
Then, in the onSave (or any on- event) put something like this;
Of course, if you want CRM to do anything with the response of the xml-request you can use the onreadystatechange for that.
Hope this may help other people. It may seem straightforward, but it took me quite a while before I figured out how to do it (although I knew how to use AJAX and .NET and stuff). I think it's a shame that the CRM developers are left out in the cold by Microsoft. They should really put some more time in documenting the SDK and how to do things like this.
只是想在这里尝试一下:
您的文件的路径位于 CRMWeb 目录内?您是否设置了虚拟目录或其他内容?
/folder/index.html 是否可以在相同形式的 IFRAME 中工作?
也许尝试一些你知道可行的方法来确保:http://stackoverflow.com 或 http://google.com。
另请注意,MS 建议将所有自定义内容放在 /ISV/ 文件夹中。它不应该导致 404 错误,但我不确定他们是否会认为这是不受支持的。
你真的在调用 html 扩展吗?我相信您需要对 aspx 和 asmx 扩展使用 prependOrgName (请参阅 SDK)。我不确定这是否会导致 404 错误,或者只是立即使用您的默认组织。
Just thinking of things to try here:
The path to your file is within the CRMWeb directory? Do you have a virtual directory set up or anything?
Does the /folder/index.html work in an IFRAME on the same form?
Maybe try something you know will work just to make sure: http://stackoverflow.com or http://google.com.
Also note that MS recommends putting all customizations in the /ISV/ folder. It shouldn't cause 404 errors, but I'm not sure if they'll consider this unsupported.
Are you really calling a html extension? I believe you need to use prependOrgName (see SDK) for aspx and asmx extensions. I'm not sure if it would cause a 404 or just use your default organization off hand though.