Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi,
I need help please.

I have wcf service, I tried to send a request using xmlhttprequest as follows:
C#
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);


In the response i get "Bad Request 400"

What is my mistake please?

Thank you
Posted

1 solution

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
 
Share this answer
 
v2
Comments
nisha4285 7-Feb-11 10:54am    
Thank you for your response i'll try...
Espen Harlinn 7-Feb-11 15:31pm    
Good answer, jQuery makes it easier :)
nisha4285 19-Feb-11 6:28am    
Hi, it's working really nice :)
But ic case that my customer still want to work in the old way, something like:
http://server/service/function?op=


what is the solution?

Thank you again

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900