呼叫WCF服务404未找到 [英] Call WCF service 404 Not Found
本文介绍了呼叫WCF服务404未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个支持AJAX的WCF服务,我想用POST调用它。但该服务未找到404,我不明白为什么。我看到一些例子,但找不到,为什么我的服务无法访问。我已经改变了我的web配置,但没有任何区别。我该怎么办错了?
I've created an AJAX-enabled WCF Service and I want call it using POST. But the service was 404 not found and i don't understand why. I saw some examples but can't find why my service is inaccessible. I've already changed my web config but there is no difference. What do I do wrong?
namespace ATSite
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class SendEmailService
{
[OperationContract]
public string HelloWorld(string id)
{
return "Hello world " + id;
}
}
}
调用该服务:
Calling the service:
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
This is my 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>
谢谢!
推荐答案
在WebInvoke属性为您提供了一些选项:
The WebInvoke attribute gives you some options:
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
public string MyAwesomeServiceMethod(Decimal value)
{
return value.ToString("F2");
}
这篇关于呼叫WCF服务404未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文