在localhost上调用wcf服务

时间:2014-12-29 13:09:18

标签: jquery wcf

function CallWcfService(str, AppName) 
{

var list = ["a"];

jQuery.support.cors = true;
jQuery.ajax({

    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: 'http://192.168.2.20/CWSERVERWCF/MainLoginService.svc/GetSubModuleTotalCountByUserAppNo',
    data: JSON.stringify({ strErrMsg: list, chrErrFlg: 'Y', pcocd: sessionStorage.getItem("CoCd"), pdiv: sessionStorage.getItem("Div"), ploc: sessionStorage.getItem("Loc"), UserId: username, ShowParameter: sessionStorage.getItem("Parameter"), AppNo: sessionStorage.getItem("AppNo") }),
    dataType: "json",
    processData: false,
    crossDomain: true,
    success: function (r) {
        ServiceSucceeded(r)
    },
    error: ServiceFailed// When Service call fails
});

}

我正在尝试调用Web服务,但每当我使用localhost而不是ip地址调用时,我都面临错误..请帮助

1 个答案:

答案 0 :(得分:0)

只有在您的计算机的IIS上托管服务时才能使用Localhost,我的意思是客户端和服务器计算机应该是相同的。要访问远程服务,您应该使用IP或域名,如果它在Internet上,或者您也可以使用机器在Intranet上命名。