我有两个网站
- 同步测试网站
- RemoteWebsite(客户端网站)
SysteTestWebsite 包含具有以下方法的 Web 服务“Service.svc”
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]<br>
public class Service
{
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
public string SyncJson(string p1)
{
return p1;
}
// Add more operations here and mark them with [OperationContract]
}
我想从 RemoteWebsite 的 HTML 页面访问此方法,以下是此 HTML 页面的代码。
function SyncJson() {
var sPhone = "test data";
var data = { p1: sPhone };
data = JSON.stringify(data);
$.ajax({
type: "POST",
contentType: "application/json;",
url: "http://mydomain:12887/Service.svc/SyncJson",
data: data,
dataType: 'json',
success: function () {
alert('success');
},
error: function (msg) {
console.log(msg);
alert(msg.d);
}
});
}
<p>
Remote site
<input type="button" onclick="SyncJson()" value="Send Test Data" />
</p>
但我得到了这个错误:
NetworkError:405 方法不允许 - http://abc.com/Service.svc/SyncJson