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?
我已经创建了一个支持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;
}
}
}
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);
}
This is my web.config
这是我的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>
Thanks!
2 个解决方案
#1
0
I don't think you can call it that way. Here is an example on how to consume a wcf service http://www.codeproject.com/Articles/42643/Creating-and-Consuming-Your-First-WCF-Service
我不认为你可以这样称呼它。以下是如何使用wcf服务的示例http://www.codeproject.com/Articles/42643/Creating-and-Consuming-Your-First-WCF-Service
#2
0
The WebInvoke attribute gives you some options:
WebInvoke属性为您提供了一些选项:
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
public string MyAwesomeServiceMethod(Decimal value)
{
return value.ToString("F2");
}
#1
0
I don't think you can call it that way. Here is an example on how to consume a wcf service http://www.codeproject.com/Articles/42643/Creating-and-Consuming-Your-First-WCF-Service
我不认为你可以这样称呼它。以下是如何使用wcf服务的示例http://www.codeproject.com/Articles/42643/Creating-and-Consuming-Your-First-WCF-Service
#2
0
The WebInvoke attribute gives you some options:
WebInvoke属性为您提供了一些选项:
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
public string MyAwesomeServiceMethod(Decimal value)
{
return value.ToString("F2");
}