views:

726

answers:

3

How can i call a wcf service from jquery (i am using asp.nt mvc). This is what i used to do with asmx webservices :

   $.ajax({
                type: "POST",
                url: "Services/MyService.asmx/DoSomething",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
             //do the magic
                });
                }
            });

How do I do the same with a WCF service?

+1  A: 

Rick Strahl has a great example, almost the same as what you have listed.

DennyDotNet
+1  A: 

Yassir,

The precise details of how you call a specific WCF service will depend on the service. For instance, is it a SOAP service, or a REST service? JSON or Plain XML.

The good news is that if your WCF service is exactly the same as your ASMX service, then you can call it in exactly the same way.

The bad news is that, if your WCF service is different, then calling it will be different.

John Saunders
I already created the service and it is working all i need is call it with jquery
Yassir
What happens when you try to call it?
John Saunders
i don't know how to call it because all the examples i found create a proxy to consume the webservice in (C# or VB)
Yassir
Please just try calling it in the EXACT same way you did with the ASMX, then see what happens. I don't know why you expect it to be totally different. You say you created the service and it's working. How did you test it? Have you tested it returning JSON? What part of calling this service do you not understand?
John Saunders
+1  A: 

Hi there,

I just posted an article explaining how to accomplish calling a WCF service using jQuery and JSON.

http://yoavniran.wordpress.com/2009/08/02/creating-a-webservice-proxy-with-jquery/

Hope it can help you.

Yoav.

poeticGeek