0
我想从其他网站调用web服务,并使用Ajax调用在html页面中获取响应。使用wcf rest web服务的ajax请求
该数据应该是web服务的响应。 我试了很多,但我没有得到任何解决方案。我还跨越了浏览器,使用ajax请求调用webservice时,问题就在那里。
我的web服务代码:
[ServiceContract]
public interface IService
{
[WebInvoke(Method = "GET",RequestFormat=WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
//[WebGet]
[OperationContract]
string GetData(string inputString);
}
It is implemented as:
public string GetData(string inputString)
{
return "myData";
}
Javascript code (From my other website):
<script type="text/javascript">
function click_btn() {
$.ajax({
type: "GET",
url: "http://192.168.15.213/MyService.svc/GetData/inputString=e",
contentType: "application/json",
success: function (jsonData) {
alert('Data: ' + jsonData);
`enter code here` },
Error: function (e) {
alert('err: ' + e);
}
});
return false;
}
</script>
我收到错误404 method not allowed
当我打电话从其他网站的web服务。