从javascript访问WCF服务

Accessing WCF Services from javascript

本文关键字:服务 WCF 访问 javascript      更新时间:2023-09-26

我有一个WCF服务。在javascript中,如何访问此服务。其中一个功能如下。如何在javascript、ajax中访问此函数。

[OperationContract]
[WebGet(UriTemplate = "Get_PersonelBilgi/Kul_Ad={kul_ad},Sifre={sifre}",
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json, 
        BodyStyle = WebMessageBodyStyle.Bare)]
Personel Get_PersonelBilgi(string kul_ad,string sifre);

如果您使用的是jQuery,您可以使用这样的代码,替换为我们的数据:

$.ajax({
        type: "GET",
        url: "http://localhost:YourPort/YourService/NameOfService.svc/Get_PersonelBilgi/Kul_Ad=0&Sifre=0",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            alert(data);
        },
        error: function (xhr) {
            alert(xhr.responseText);
        }
    });