我已经创建了一个web服务来使用javacript来警告hello world。但没有结果。甚至没有错误。我无法弄清楚我在哪里犯了错误。我只是在本地托管wsdl。我错过了什么?
这是我的代码
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="~/css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/NetWebsite/js/jquery-1.10.2.js" ></script>
<script type="text/javascript" src="/NetWebsite/js/script.js" ></script>
<script language="JavaScript">
var iCallID;
function InitializeService(){
service.useService(http://localhost:5431/WebSite1/WebService.asmx?WSDL,"HelloWorldService");
service.HelloWorldService.callService("HellowWorld");
}
function ShowResult(){
alert(event.result.value);
}
</script>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body onload="InitializeService()" id="service"
style="behavior:url(webservice.htc)" onresult="ShowResult()">
<form runat="server">
<div class="page">
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
<div class="clear">
</div>
</div>
<div class="footer">
</div>
</form>
</body>
</html>
答案 0 :(得分:1)
首先,您忘记了服务地址中的引号。它应该是:
service.useService("http://localhost:5431/WebSite1/WebService.asmx?WSDL","HelloWorldService");
其次,您无法初始化服务并获得相同DOM元素的结果。 例如,在BODY中初始化,然后在DIV中得到结果。 这里有更多细节: http://www.webreference.com/js/column99/7.html