如何从jQuery调用WCF Web服务?

时间:2022-10-30 21:46:11

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

如何从jquery调用wcf服务(我正在使用asp.net mvc)。这就是我以前用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?

如何使用WCF服务执行相同操作?

3 个解决方案

#1


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

Rick Strahl有一个很好的例子,几乎和你列出的一样。

#2


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.

您如何调用特定WCF服务的具体细节将取决于服务。例如,它是SOAP服务还是REST服务? JSON或纯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.

好消息是,如果您的WCF服务与ASMX服务完全相同,那么您可以用完全相同的方式调用它。

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

坏消息是,如果您的WCF服务不同,那么调用它将是不同的。

#3


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

我刚刚发布了一篇文章,解释了如何使用jQuery和JSON完成调用WCF服务。

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

Hope it can help you.

希望它可以帮到你。

Yoav.

#1


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

Rick Strahl有一个很好的例子,几乎和你列出的一样。

#2


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.

您如何调用特定WCF服务的具体细节将取决于服务。例如,它是SOAP服务还是REST服务? JSON或纯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.

好消息是,如果您的WCF服务与ASMX服务完全相同,那么您可以用完全相同的方式调用它。

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

坏消息是,如果您的WCF服务不同,那么调用它将是不同的。

#3


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

我刚刚发布了一篇文章,解释了如何使用jQuery和JSON完成调用WCF服务。

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

Hope it can help you.

希望它可以帮到你。

Yoav.