js调用本项目的wcf服务器,js调用wcf rest服务问题

当前位置:编程学习 > C#/ASP.NET >>

js调用wcf rest服务问题

这是接口代码:

namespace WcfService

{

// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService1”。

[ServiceContract]

public interface IService1

{

[OperationContract]

[WebInvoke(Method = "POST", UriTemplate = "GetData", ResponseFormat = WebMessageFormat.Json)]

string GetData();

}

}

下面是实现接口的svc文件代码

namespace WcfService

{

// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“Service1”。

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

public class Service1 : IService1

{

public string GetData()

{

return string.Format("You entered: {0}", 0);

}

}

}

web.config 配置如下:

页面调用代码如下:

function LoadData(callback) {

Ext.Ajax.request({

url: "http://localhost/WcfService/Service1.svc/GetData",

method: 'POST',

scope: this,

timeout: 200000,

success: function (response) {

if (callback)

callback(response.responseText, this);

try {

lockUI(this, false);

}

catch (e) { }

},

failure: function (e) {

if (showErrMsg)

try {

lockUI(this, false);

}

catch (e) { }

}

});

}

function callback(res) {

alert(res);

}

现在的问题是只要在前台那里调用LoadData这个函数的时候就返回 failure异常信息是 state 400,这个我知道是找不到那个连接,但是单独在浏览器上面运行http://localhost/WcfService/Service1.svc是可以找到的,在后面加相应的方法就不行了,是不是我的配置文件哪里有问题,跪求答案,所有的代码都贴上了。

rest

wcf

interface

异常

--------------------编程问答--------------------

[WebInvoke(Method = "Get",

直接浏览

http://localhost/WcfService/Service1.svc/GetData

然后断点 调试,只能帮你到这里了~

--------------------编程问答--------------------

没有用啊,GET和POST都是同样的效果

--------------------编程问答--------------------

是不是分数不够啊

--------------------编程问答--------------------

都没有人来看,求观看啊

--------------------编程问答--------------------

--------------------编程问答--------------------

是否 在一个域,调用的时候  Service是否已启动

--------------------编程问答--------------------

同在一个域里面的,是不是web.config里面配置不对啊,我看到人家都是这么写的,要这么启动Service

--------------------编程问答--------------------

自己路过,仍然希望高手出现

--------------------编程问答--------------------

希望有个例子

补充:.NET技术 , ASP.NET