【发布时间】:2014-03-04 10:48:29
【问题描述】:
我正在尝试使用 jquery 从 MVC(razor) 调用我的 WCF 方法,然后出现错误
- 请求网址:localhost:8377/Service/ajaxServiceEstimate.svc/Location
- 请求方法:POST 状态
- 代码:HTTP/1.1 404 未找到
网络配置
<system.serviceModel>
<services>
<service name="Estimate.Service.ajaxServiceEstimate" behaviorConfiguration="Estimate.Service.ajaxServiceEstimate" >
<endpoint address="" behaviorConfiguration="Estimate.Service.ajaxServiceEstimateAspNetAjaxBehavior"
binding="webHttpBinding" contract="Estimate.Service.ajaxServiceEstimate" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="Estimate.Service.ajaxServiceEstimateAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Estimate.Service.ajaxServiceEstimate" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
服务代码
namespace Estimate.Service
{
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ajaxServiceEstimate
{
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}
// Add more operations here and mark them with [OperationContract]
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)]
public string Location()
{
return "anurag";
}
}
}
jQuery 代码:
<script src="~/Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
function GetTeamData() {
$.ajax(
{
async: true,
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://localhost:8377/Service/ajaxServiceEstimate.svc/Location",
dataType: "json",
data: '{}',
success: function (content) {
DisplayRun(map, content);
}
});
}
</script>
<div>
<input id="btnSave" type="button" value="Save" onclick="GetTeamData();" />
<div id="divOutput"></div>
</div>
【问题讨论】:
-
你能在任何情况下解析 localhost:8377/Service/ajaxServiceEstimate.svc/Location 吗?
-
嗨 NWard,我试过“~/Service/ajaxServiceEstimate.svc/Location”这个和“../Service/ajaxServiceEstimate.svc/Location”这个
标签: jquery asp.net-mvc wcf razor