我创建了一个支持 AJAX 的 WCF 服务,我想使用 POST 调用它。但是该服务是 404 未找到,我不明白为什么。我看到了一些示例,但找不到我的服务无法访问的原因。我已经更改了我的网络配置,但没有区别。我做错了什么?
namespace ATSite
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class SendEmailService
{
[OperationContract]
public string HelloWorld(string id)
{
return "Hello world " + id;
}
}
}
调用服务:
function helloWorld() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "../SendEmailService.svc/HelloWorld",
data: '{"Id": "2"}',
dataType: "json",
success: function (result) {
onSuccess(result);
},
error: alert('Erro')
});
}
function onSuccess(result) {
alert(result);
}
这是我的 web.config
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="ATSite.SendEmailServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="ATSite.SendEmailService">
<endpoint address="" behaviorConfiguration="ATSite.SendEmailServiceAspNetAjaxBehavior"
binding="webHttpBinding" contract="ATSite.SendEmailService" />
</service>
</services>
</system.serviceModel>
谢谢!