【发布时间】:2015-04-23 06:17:24
【问题描述】:
直到最近,我们一直在 Dynamics CRM 2011 应用程序中使用 RU 11,但最近开始了一个最终迁移到 CRM 2015 的项目。我们已经升级到 RU 12,这就是有趣的地方!
我已经设法解决了许多以前存在但终生无法解决访问外部 Web 服务、沿途传递参数和检索数据的问题。
起初我在使用“CreateXmlHttp()”函数时遇到了问题,但在网上找到了一个很好的答案,表明以下函数会有所帮助:
function CreateXmlHttp()
{
var ref = null;
if (window.XMLHttpRequest) {
ref = new XMLHttpRequest();
} else if (window.ActiveXObject) { // Older IE
ref = new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
return ref;
}
这工作正常,正如预期的那样,我现在可以连接到服务了。
但是,我没有检索任何数据,这是让我陷入困境的问题。
作为背景,以下是我在将 xml 发布到 web 服务之前声明一些整数变量的代码。
parseInt(lngLicensNr);
parseInt(lngNrOfUsers);
parseInt(lngAnnualWorkingTime);
parseInt(lngIncludedHours);
parseInt(productType);
if (licenceType == 100000000) {
var licenseType = "ltUnlimitedMode";
lngIncludedHours = 1000000;
}
if (licenceType == 100000001) {
var licenseType = "ltHourlyMode";
}
if (lngLicensNr != null && lngNrOfUsers != null && lngAnnualWorkingTime != null && lngIncludedHours != null && productType != null && licenseType != null) {
var errMsg = "";
var errCount = 0;
var xml = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";
xml += "<soap:Body>";
xml += "<GetBaseInstallationKey xmlns=\"http://www.keyservice.com/\">";
xml += "<licensNr>" + lngLicensNr + "</licensNr>";
xml += "<nrOfUsers>" + lngNrOfUsers + "</nrOfUsers>";
xml += "<annualWorkingTime>" + lngAnnualWorkingTime + "</annualWorkingTime>";
xml += "<includedHours>" + lngIncludedHours + "</includedHours>";
xml += "<productType>" + baseProduct + "</productType>";
xml += "<licenseType>" + licenseType + "</licenseType>";
xml += "</GetBaseInstallationKey>";
xml += "</soap:Body>";
xml += "</soap:Envelope>";
try {
Request = CreateXmlHttp();
} catch (ex) {
alert("An error occured while accessing the webservice.\n\n1. " + ex.name + " \n " + ex.message + "\n\n");
errCount = 1;
}
if (errCount == 0) {
try {
Request.open("POST", "http://web01:8080/KeyWebService/KeyWebService.asmx", false);
} catch (ex) {
alert("An error occured while accessing the webservice.\n\n2. " + ex.name + " \n " + ex.message + "\n\n");
errCount = 1;
}
}
if (errCount == 0) {
try {
Request.setRequestHeader("SOAPAction", "http://www.keyservice.com/GetKey");
Request.setRequestHeader("Host", "web01:8080");
Request.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
Request.setRequestHeader("Content-Length", xml.length);
Request.send(xml);
var xmlDoc = Request.responseXML;
} catch (ex) {
alert("An error occured while accessing the webservice.\n\n3. " + ex.name + " \n " + ex.message + "\n\n");
errCount = 1;
}
}
if (errCount == 0 || Request.responseXML != null) {
baseKey = Request.responseXML.text;
} else {
baseKey = "No key generated";
}
}
if (lngLicensNr == null || lngNrOfUsers == null || lngAnnualWorkingTime == null || lngIncludedHours == null || productType == null || licenseType == null) {
alert('Not all parameters have been entered - it is not possible to generate a key without all parameters');
}
在 RU 12 之前,代码运行良好,最后一个变量“baseKey”是从 Web 服务中检索到的。
但是,现在整个过程运行良好,因为它似乎连接正常,但只是没有从服务中检索“baseKey”。
我认为该问题可能与已弃用的端点或架构有关,甚至可能与返回并显示值的已弃用代码有关(即 var xmlDoc = Request.responseXML;),但我不确定在哪里解决。
如果有人有任何想法或可以为我指出正确的方向,那将是一个很大的帮助。
【问题讨论】:
标签: javascript web-services soap dynamics-crm-2011