1

我需要从 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, Version=4.0.0.0, Culture=neutral, 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 写入一个单词,所以那里没有什么特别的......

4

2 回答 2

1

好的,我发现了这个想法是什么。如果您想从 CRM 4.0 对动态 .NET 应用程序执行 AJAX 调用,请执行以下操作。

将 .NET 应用程序的程序集放在 CRM 文件夹中的 CRMWeb/bin 文件夹中。将您的 aspx 文件放在 ISV 文件夹中的文件夹中。我使用了 stunnware.com 文件夹,因为它在那里,但为了整洁起见,您可能需要创建另一个文件夹。然后,在 onSave (或任何 on- 事件)中放置类似这样的内容;

var xmlHttp = null;
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

var getstr = "foo=bar&foo2=bar2";
var url = prependOrgName("/ISV/*YOURFOLDER*/Default.aspx?"+getstr);

xmlHttp.open("GET",url,true);
xmlHttp.send(null);

当然,如果您希望 CRM 对 xml 请求的响应做任何事情,您可以使用 onreadystatechange。

希望这可以帮助其他人。这看起来很简单,但我花了很长时间才弄清楚如何去做(虽然我知道如何使用 AJAX 和 .NET 之类的东西)。我认为 CRM 开发人员被微软冷落是一种耻辱。他们真的应该花更多的时间来记录 SDK 以及如何做这样的事情。

于 2009-12-09T19:17:39.863 回答
0

只是想在这里尝试的事情:

您的文件的路径是在 CRMWeb 目录中吗?您是否设置了虚拟目录或其他任何东西?

/folder/index.html 是否在同一表单上的 IFRAME 中工作?

也许尝试一些你知道会起作用的东西,以确保: http://stackoverflow.comhttp://google.com

另请注意,MS 建议将所有自定义项放在 /ISV/ 文件夹中。它不应该导致 404 错误,但我不确定他们是否会认为这不受支持。

你真的在调用html扩展吗?我相信您需要为 aspx 和 asmx 扩​​展使用 prependOrgName(请参阅 SDK)。我不确定它是否会导致 404 或者只是使用您的默认组织。

于 2009-12-01T14:23:50.620 回答