猿问

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

如题:

我试图在一个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

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

慕容708150
浏览 618回答 1
1回答
随时随地看视频慕课网APP
我要回答