我们使用Netbeans创建了用于温度转换的Web服务。它工作正常。
@WebMethod(operationName = "tempConverter")
public Double tempConverter(@WebParam(name = "temp") double temp,
@WebParam(name = "choice") int choice) {
switch(choice)
{
case 1:
tempConv = (9.0/5.0)*(ip)+32.0;
break;
case 2:
tempConv = (5.0/9.0)*(ip-32.0);
break;
}
return tempConv;
}
但是我们想在html中使用这个Web服务。 chanService是webservice的名称。
代码是:
<script language="javascript">
function initialize()
{
service.useService("http://localhost:8080/chanService/chanService.java?WSDL","tempConverterService");
}
function getTemp()
{
var temp,choice;
temp=document.getElementById('temp').value;
choice=document.getElementById('choice').value;
service.tempConverterService.callService(tempConverter,temp,choice);
}
function Result()
{
alert(event.result.value);
}
</script>
</head>
<body onload="initialize()" id="service" onresult="Result()">
<form name="form1">
<input type="text" name="temp" id="temp" value="0" size="50" />
<input type="text" name="choice" value="1" id="choice" size="50" />
<input type="button" value="Submit" name="submit" onclick="getTemp()"/>
</form>
但这不起作用。请帮忙,
答案 0 :(得分:0)
您需要在body标记中添加style =“behavior:url(webservice.htc)”并将文件放在页面的同一文件夹中。
请参阅此http://msdn.microsoft.com/en-us/library/ie/ms531063(v=vs.85).aspx