首页 新闻 会员 周边

Ajax-enabled WCF Service和普通的WCF Service有什么区别?

0
悬赏园豆:5 [已解决问题] 解决于 2011-04-10 11:11

如题:

我试图在一个web的客户端,利用Script Manager控件去加载一个普通的WCF Service,代码如下:

html 代码

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>

<script type="text/javascript">
function OnTest() {
var ajaxClient = new AjaxTest1.IHelloWorldService();
ajaxClient.DoWork(OnComplete, OnError);
}

function OnComplete(result) {
document.getElementById(
"txt").value = result.toString();
}

function OnError(result) {
alert(result.toString());
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="http://localhost/WCFTest/HelloWorldSVC.svc" />
</Services>
</asp:ScriptManager>
<input id="txt" type="text" />
<input type="button" onclick="OnTest()" value="Button" />
</div>
</form>
</body>
</html>

 WCF 代码

[ServiceContract(Namespace = "AjaxTest1")]
public interface IHelloWorldService
{
[OperationContract]
string DoWork();
}
[ServiceBehavior(TransactionIsolationLevel = IsolationLevel.Serializable)]
[AspNetCompatibilityRequirements(RequirementsMode
= AspNetCompatibilityRequirementsMode.Allowed)]
public class HelloWorldService : IHelloWorldService
{
public string DoWork()
{
return "Hello World!";
}
}

但是总是提示如下错误:

Error: 'AjaxTest1' is undefined

哪个大虾帮帮忙????小弟在此拜谢~~~

dbms的主页 dbms | 初学一级 | 园豆:75
提问于:2011-04-07 10:28
< >
分享
最佳答案
0

配置是否都正常了,估计配置不正确? 参考 http://www.pczpg.com/a/2010/0813/17165.html

收获园豆:5
2012 | 高人七级 |园豆:21230 | 2011-04-07 12:46
我问题里面用的不是Ajax-enabled WCF Service,而是用的普通的WCF Service,如果单纯支持Ajax或者普通的WCF Service都可以,现在我想两者同时支持,不知道有没有什么好的解决方案???
dbms | 园豆:75 (初学一级) | 2011-04-07 13:30
同一个服务既可以支持ajax又能普通的使用,原理上可以实现,但比较复杂,最简单的方法还是公布两个服务,两个服务可以共用一个基类
参考两者的区别 http://forums.silverlight.net/forums/p/15771/52145.aspx
或者使用Data Service的方法,参考: http://www.cnblogs.com/2018/category/262512.html
2012 | 园豆:21230 (高人七级) | 2011-04-07 16:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册