通过Javascript调用WCF服务 [英] Invoking WCF Service through Javascript
问题描述
如何通过 JavaScript 访问 WCF 服务?我的问题是,我必须通过 JavaScript 访问操作合同(我的网站未启用 Ajax).
以前用于调用 .asmx Web 服务,我正在使用以下代码片段
How can I access the WCF Service through JavaScript?
My problem is, I have to access the operation contracts through the JavaScript (my website is not Ajax enabled).
Previously for calling .asmx web services,
I am using the following code snippet
var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open("POST", URL, false);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send(payload);
xmlData = xmlHttp.responseXML;
其中 url 是我的网络服务位置.
where url is my webservice location.
现在,如果我尝试以相同的方式使用 wcf 服务,则无法使用.许多技术人员正在通过 AJAX 方法进行解释,我需要一种没有 AJAX 的方法.
Now if I am trying to consume the wcf service in the same manner, I am not able to. Many techies are explaining through AJAX approach, I need an approach without AJAX.
推荐答案
通过使用 XMLHTTP,您就是在使用 ajax.
By using XMLHTTP you ARE using ajax.
这里有一个完整的例子:
There's a full example here:
这篇关于通过Javascript调用WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!