Click here to Skip to main content
15,913,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I am trying to call WCF Service from other project using the local address. I have two projects in same solution explorer. One project has the services and the other is a web application where I am using Ajax in javascript to call the WCF Service.
Following is my javascript code,
JavaScript
function sclick() {
    alert("m here");
    $.ajax({
        type: "POST",
        url: "http://localhost:4780/Service1.svc/myfunction",
        contentType: "application/json; charset=utf-8 ",
        dataType: "json",
        success: success,
        error: fail
    })

}

function success(result) {
    alert(result);
    //alert("Success" + result.myfunctionResult);
}

function fail(result) {
    alert("Fail..... " + result.statusText + ": " + result.status);
}


flow goes to success funtion but I get null in result object. URL in ajax part is the URL I got by viewing the service1.svc file in browser.
Can anyone please tell me where I am going wrong!
Posted
Comments
Mahesh Bailwal 18-Jun-13 3:21am    
Add break point in your WCF service and debug whether service is sending proper response.
Vinay Kumar Tiwary 18-Jun-13 4:37am    
Thanks Mahesh. I tried your way. The service is sending proper response. If I put the same file in my WCF Service project then its working fine but when I am trying in other project it gives me null..:(
IpsitaMishra 18-Jun-13 4:02am    
Have a look on these links it may help you

http://www.yaplex.com/java-script/how-to-call-wcf-services-from-javascript-jquery-and-asp-net-ajax/

http://msdn.microsoft.com/en-us/library/bb924552.aspx
Vinay Kumar Tiwary 18-Jun-13 23:50pm    
hey thanks for the link.. I tried it, but result.d is not working. I am not getting why its returning null. break point in service shows proper value but when it comes to javascripts it becomes to null.. :/

1 solution

Try:
JavaScript
success: function (msg) {
alert(msg.d);
}
 
Share this answer
 
Comments
Vinay Kumar Tiwary 18-Jun-13 4:08am    
thanks zafar for your reply but msg.d works in web service, it is WCF service. Even though I tried this.

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