使用xmlhttprequest访问WCF服务 [英] Access WCF service using xmlhttprequest

查看:93
本文介绍了使用xmlhttprequest访问WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要帮助.

我有wcf服务,我尝试使用xmlhttprequest发送请求,如下所示:

Hi,
I need help please.

I have wcf service, I tried to send a request using xmlhttprequest as follows:

var xhr;

if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
    xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
else {
    throw new Error("Could not create XMLHttpRequest object.");
}

xhr.open("POST", "http://localhost/wcfService/service.svc/GetStatus", true);

xhr.onreadystatechange = function() {
    if (xhr.readyState === 4) {
        alert(xhr.responseText);

    }
};
xhr.setRequestHeader("content-type", "text/xml; charset=utf-8");

var postData = '{id:"E757A1EA-AE50-4A0A-8DE1-26345DDDBD0A" }';
xhr.send(postData);



在响应中,我收到错误请求400"

请问我是什么错误?

谢谢



In the response i get "Bad Request 400"

What is my mistake please?

Thank you

推荐答案

请关注以下CP文章:正在调用使用jQuery的WCF服务 [ ^ ]
它使用jQuery,但也应该易于适应以使用其他javascript库.有很多成熟的跨浏览器兼容的javascript库,所以我的建议是不要按照您概述的方式进行AJAX.请改用PrototypeJS或jQuery.

最好的问候,
曼弗雷德(Manfred)
Please regard this CP article: Calling WCF Services using jQuery[^]
It uses jQuery, but should be easily adaptable to use other javascript libraries as well. There are a bunch of mature cross browser compatible javascript libraries out there so my advice is not to do AJAX in the way you outlined. Use PrototypeJS or jQuery instead.

Best Regards,
Manfred


这篇关于使用xmlhttprequest访问WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆