我正在尝试使用Ext.js从WCF获取数据。我想点击一个按钮获取所有数据。这是我到目前为止所尝试的:
这是我的JavaScript函数:
buttonClick: function () {
var myparams = { 'name': 'baris' };
Ext.Ajax.request({
url: 'http://localhost:57044/www/HelloWorldService.svc/GetMessage',//replace with ajax call
//params: Ext.encode(myparams),
method: 'GET',
type: 'ajax',
success: function (response, opts) {
if (response.responseText) {
Ext.MessageBox.alert('Success', response.responseText);
}
else {
Ext.MessageBox.alert('Failed', 'Unable to get');
}
},
failure: function (response, opts) {
alert("failure="+response.responseText);
}
});
}
这是我的网络服务界面代码:
namespace Mobile.Service.Maintenance
{
[ServiceContract]
interface IHelloWorldService
{
[OperationContract]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
String GetMessage();
}
}
这是Web服务类代码:
namespace Mobile.Service.Maintenance
{
public class HelloWorldService : IHelloWorldService
{
public String GetMessage()
{
return "Hello world from " + "baris" + "!";
}
}
}
我使用this教程实现了WCF服务。我创建了一个控制台应用程序并使用了WCF,但是我没有使用Ext.js和Ajax做同样的事情。如果我单击该按钮,它将始终返回到失败功能。在失败函数response.responseText输出一个空字符串。
我在Firebug中收到此错误:
NetworkError:400错误请求 - http://localhost:57044/www/HelloWorldService.svc/GetMessage?_dc=1399642562150
(YanıtBaşlıkları=响应标题,İstemBaşlıkları=请求标题抱歉土耳其语本地化)
提前谢谢。
这是来自萤火虫的截图。
