直到最近,我們一直在我們的Dynamics CRM 2011應用程序中使用RU 11,但最近開始了一個項目,最終遷移到CRM 2015.我們已經升級到RU 12,這就是事情變得有趣的地方!使用JavaScript CRM 2011 RU 12(彙總12)調用外部Web服務
我已經設法解決了以前存在的很多編碼問題,但無法解決我們訪問外部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;
}
這工作得很好,並如預期,它會出現這我現在可以連接到該服務。
但是,我沒有檢索任何數據,這是綁在我身上的問題。
作爲背景,以下是我的代碼來聲明一些整數變量之前通過到web服務的xml。
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;),但我不確定在哪裏解決。
如果任何人有任何想法或可以指向正確的方向,這將是一個很大的幫助。
嗨 - 非常感謝您的回答,雖然我不太確定它在這個場合能幫助我。 .GetResponse()是一個標準函數,還是它在代碼中的其他位置定義的函數? – Mark
@Mark它是調用「Rest WebService」的標準函數 –