看不出什么错误。下面的代码是可以运行的。<script language="javascript">
<!--
var iCallID;
function InitService()
{
divWSBehavior.useService("http://localhost/ProductManager/Pricing.asmx?WSDL","ProductPrice");
}
function GetProductPrice()
{
var sProductName;
sProductName = document.frmServer.txtGetPrice.value;
//iCallID = divWSBehavior.ProductPrice.callService("GetPrice",sProductName);
iCallID = divWSBehavior.ProductPrice.callService("HelloWorld");
}
function showhelloword()
{
alert(event.result.value)
}
<INPUT id="txtGetPrice" type="text"> <INPUT type="button" value="GetPrice" onclick="GetProductPrice();">
</form>
<DIV id="divWSBehavior" style="behavior:url(webservice.htc)" onresult="showhelloword()"></DIV>然后就是
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
<!--
var iCallID;
function InitService()
{
divWSBehavior.useService("http://localhost/ProductManager/Pricing.asmx?WSDL","ProductPrice");
}
function GetProductPrice()
{
var sProductName;
sProductName = document.frmServer.txtGetPrice.value;
//iCallID = divWSBehavior.ProductPrice.callService("GetPrice",sProductName);
iCallID = divWSBehavior.ProductPrice.callService("HelloWorld");
}
function showhelloword()
{
alert(event.result.value)
}
<INPUT id="txtGetPrice" type="text"> <INPUT type="button" value="GetPrice" onclick="GetProductPrice();">
</form>
<DIV id="divWSBehavior" style="behavior:url(webservice.htc)" onresult="showhelloword()"></DIV>然后就是
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
解决方案 »
- 示意图软件
- 怎么研究那些大型的ASP.NET项目
- ****** 请大家推荐一套人才系统,要源码,Money 也可 **********
- 如何获取数据库中的自动增长列
- 那位兄弟帮我解释这段关于FormsAuthentication的代码是什么意思?Thanks..
- 50 分,问一个问题!将应用程序部署到虚拟空间中!运行时报“未将对象引用设置到对象的实例。”
- asp.net中如何截取字符串长度?
- 急!!!!!!
- 问个简单的问题, 在DataGrid上修改记录的时候....
- datagrid控件是不是大多用来做查询时显示数据用的?如果表格的字段很多,而且有的字段很长,用datagrid做起来不美观,请问各位都用什么办
- 在asp.net中如何查询数据并给出结果显示在页面上?
- 请问做一个网站程序使用session好 还是用cookie好呢?
*.htm
<script>
function Call()
{
var objhttp=new ActiveXObject("Microsoft.XMLHTTP")
var xmldoc=new ActiveXObject("Microsoft.XMLDOM")
var strWebserviceURL="http://localhost/WebService1/Service1.asmx/Password" ;
var strRequest="s=dd" ;
objhttp.open ("post",strWebserviceURL,false);
objhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") ;
objhttp.send(strRequest)
//装载
if (xmldoc.load(objhttp.responseXML)) //成功
{
var rootNode =xmldoc.documentElement
alert(rootNode.firstChild.xml);
} //8
}
</script>
<html>
<body>
<input type=button onclick=Call() value="ok">
</body>
</html>
////Service1.asmx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;namespace WebService1
{
/// <summary>
/// Service1 的摘要说明。
/// </summary>
//[WebService(Namespace="http://localhost/webserver/")]
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
} #region 组件设计器生成的代码
//Web 服务设计器所必需的
private IContainer components = null;
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion // WEB 服务示例
// HelloWorld() 示例服务返回字符串 Hello World
// 若要生成,请取消注释下列行,然后保存并生成项目
// 若要测试此 Web 服务,请按 F5 键 [WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string Password(string s)
{
byte []ss;
ss=System.Text.Encoding .UTF8 .GetBytes(s) ;
string sss=null;
foreach (byte e in ss)
{
sss+=e.ToString ();
}
return sss; }
}
}
{
document.all.divWSBehavior.useService("http://localhost/WebApplication2/Service1.asmx/?WSDL","ProductPrice");
}
{
document.all.divWSBehavior.useService("http://localhost/WebApplication2/Service1.asmx/?WSDL","ProductPrice");
}
function HandleClick()
{
var s1,s2;
s1="Hello";
s2="Word";
iCallID = document.all.divWSBehavior.ProductPrice.callService(strtext,"strtext",s1,s2);
}
=====================
这样子不行。还是提示document.all.divWSBehavior.ProductPrice.callService 为空或不是对象
这个也一样的,不知道为什么就是为空或不是对象
ProductPrice 这个属性是自己创建的。
如果不是 undefined 就
alert(document.all("divWSBehavior").ProductPrice);
如果不是 undefined 就
alert(document.all("divWSBehavior").ProductPrice.callService);看是哪一步弹出undefined 就知道是哪个属性没有找到了。
如果不是 undefined 就
alert(document.all("divWSBehavior").ProductPrice);前面二个是undefined ??为什么是没找到呢?第五个是未定义document.all("divWSBehavior").ProductPrice.callService
是要实现客户端调用webservice吗
==========================
是的。我参照别的代码就是实现不了。
代码都是一样的,偏偏我的是divWSBehavior.ProductPrice.callService 为空或不是对象
alert(document.all("divWSBehavior").ProductPrice);//能不能找到,我不知道,估计是这里的问题,你测试一下,找找问题,如果这一步弹出undefined就是有问题了
alert(document.all("divWSBehavior").ProductPrice); 弹出的也是undefinded. to jsijy(小卢)我有webservice.htc 这个文件