jQuery.POST:调用未调用的WCF服务!

jQuery.POST:调用未调用的WCF服务!,wcf,jquery,wcf-client,jquery-post,Wcf,Jquery,Wcf Client,Jquery Post,由于我试图向我的WCF服务发出POST请求,我无法发布服务请求,无法获得响应。 我使用的是WebHttpBinding,我的WCF服务托管在Windows服务中带有端口8181 WCF服务方式: [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "/{cstid}/{deptid}/get/customer/?cstname={cstname}", BodyStyle = WebMessageBodyStyle.

由于我试图向我的
WCF服务发出POST请求
,我无法
发布服务请求
无法获得响应。

我使用的是WebHttpBinding,我的
WCF服务托管在Windows服务中
带有
端口8181

WCF服务方式:

[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/{cstid}/{deptid}/get/customer/?cstname={cstname}", 
    BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json)]
Customer CustomerGet(string cstid, string deptid, string cstname);
JQuery发布方法

jQuery.ajax({
    type: 'POST',
    url: 'http://localhost:8181/mysite/e48/91/get/customer/?',
    dataType: 'json',
    contentType: "application/json; charset=utf-8",
    processData: false,
    success: function (data) {
        alert(data);  // not getting anything  :(
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        alert('Error :' + textStatus);
    }
});
有谁能告诉我为什么我不能打电话给这项服务,我将如何解决这个问题

提前谢谢

您的模板:

/{cstid}/{deptid}/get/customer/?cstname={cstname}
您的jQuery URL:

/e48/91/get/customer/?

看起来您缺少
cstname
,因此运行时的值将为null,因为不需要查询字符串参数来匹配UriTemplate。您没有显示您的实现,但我猜您无论如何都会查找
客户
接受null,但没有找到实际实例,只是返回null。

因为您的UriTemplate是

 UriTemplate = "/{cstid}/{deptid}/get/customer/?cstname={cstname}",
您至少应该为{cstname}传递一个参数。例如,尝试以下方法:

jQuery.ajax({
type: 'POST',
url: 'http://localhost:8181/mysite/e48/91/get/customer/?',
data: { cstname: "nunu" },
dataType: 'json',
contentType: "application/json; charset=utf-8",
processData: false,
success: function (data) {
    alert(data);  // not getting anything  :(
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
    alert('Error :' + textStatus);
}});

在我看来,将WCF Web Http服务用于WebGet操作以外的任何操作都是非常麻烦的。

您是否将firefox与firebug一起使用?控制台中是否显示了post?响应是什么样子的?我没有答案,但这是否使用了用于WCF的REST工具包?是不是在构造的jquery调用中缺少了服务url的查询字符串?我认为存在跨域发布的问题,因为我使用端口运行我的MVC站点,而我的WCF服务使用端口托管。。。你知道我该如何解决这个问题吗?我想这是一个跨域发布的问题,因为我用端口运行我的MVC站点,而我的WCF服务用端口托管。。。知道我该怎么解决吗?知道。尝试(a)使用tyoe:“GET”而不是POST,或者(b)根本不指定contentType。对我来说,我总是能工作。对于3个字符串参数,为什么需要执行POST?使用GET容易得多,失败的可能性也小得多,这就是为什么我几乎总是使用类型:“GET”。这是因为很难让WCF服务与POST一起正常工作。如果可能,请使用WebGet而不是WebInvoke我认为存在跨域发布问题,因为我正在使用端口运行我的MVC站点,而我的WCF服务使用端口托管。。。你知道我该如何解决这个问题吗?