如题:
我试图在一个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
哪个大虾帮帮忙????小弟在此拜谢~~~
配置是否都正常了,估计配置不正确? 参考 http://www.pczpg.com/a/2010/0813/17165.html