【发布时间】:2017-05-06 12:37:21
【问题描述】:
我有一个带有 javascript 和 Ajax POST 的简单 HTML 页面,用于调用我制作的 WCF WebService。
HTML 页面的作用是从用户输入中收集所有信息,将其包装在 json 中,然后调用 web 服务。
webservice 应该接收 Ajax POST,将 json 反序列化为一个对象并将其插入 DB。
我在我的本地 IIS 服务器下发布了 WCF 服务,但我收到错误 404 未找到。我还将 HTML 页面托管在不同的应用程序中,在同一个网站下,在同一个 IIS 本地主机中。
可能是什么问题?我正在尝试修复此问题 2 天,但没有成功。
这是我的代码:
Ajax 帖子:
$.ajax({
type: 'POST',
crossDomain: true,
dataType: 'json',
url: "http://localhost/wcf_test/Service1/InsertUpdateIndividualEpxert",
data: JSON.stringify({individualExpert}),
contentType: "application/json; charset=utf-8",
success: onDataReceived,
error: onDataError
});
function onDataReceived(data)
{
console.log('Everything is good!');
}
function onDataError()
{
console.log('Not working mister!');
}
WCF 接口:
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "InsertUpdateIndividualEpxert/{json}")]
void InsertUpdateIndividualEpxert(string json);
WCF Web.Config:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="Service1_HttpBinding">
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="Service1_EndpointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Service1_ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Service1_ServiceBehavior" name="WS_Experts.Service1">
<endpoint address=""
behaviorConfiguration="Service1_EndpointBehavior"
binding="webHttpBinding"
bindingConfiguration="Service1_HttpBinding"
contract="WS_Experts.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
【问题讨论】: