看不出什么错误。下面的代码是可以运行的。<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";
}

解决方案 »

  1.   

    给你一个例子:
    *.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; }
    }
    }
      

  2.   

    如果我会xmlhttp就不会web service了
      

  3.   

    把Javascript程序写在</body>后面!!
      

  4.   

    function InitService()
    {
    document.all.divWSBehavior.useService("http://localhost/WebApplication2/Service1.asmx/?WSDL","ProductPrice");
    }
      

  5.   

    function InitService()
    {
    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 为空或不是对象
      

  6.   

    document.all("divWSBehavior").ProductPrice.callService
      

  7.   

    如果divWSBehavior有ProductPrice的属性,就是这么写的。
      

  8.   

    document.all("divWSBehavior").ProductPrice.callService======================
    这个也一样的,不知道为什么就是为空或不是对象
      

  9.   

    如果divWSBehavior有ProductPrice的属性,就是这么写的。
    ProductPrice 这个属性是自己创建的。
      

  10.   

    alert(document.all("divWSBehavior"));
    如果不是 undefined 就
    alert(document.all("divWSBehavior").ProductPrice);
    如果不是 undefined 就
    alert(document.all("divWSBehavior").ProductPrice.callService);看是哪一步弹出undefined 就知道是哪个属性没有找到了。
      

  11.   

    alert(document.all("divWSBehavior"));
    如果不是 undefined 就
    alert(document.all("divWSBehavior").ProductPrice);前面二个是undefined ??为什么是没找到呢?第五个是未定义document.all("divWSBehavior").ProductPrice.callService
      

  12.   

    是要实现客户端调用webservice吗
      

  13.   

    回复人: jsljy(小卢) ( ) 信誉:97  2004-03-16 14:26:00  得分:0 
     
     
      是要实现客户端调用webservice吗
      
     
    ==========================
    是的。我参照别的代码就是实现不了。
    代码都是一样的,偏偏我的是divWSBehavior.ProductPrice.callService 为空或不是对象
      

  14.   

    webservice.htc这个文有没有
      

  15.   

    楼主,你的短信回不了,坛子出了问题吧。alert(document.all("divWSBehavior")); //这应该是可以找到的。我看了代码,没什么问题。但是
    alert(document.all("divWSBehavior").ProductPrice);//能不能找到,我不知道,估计是这里的问题,你测试一下,找找问题,如果这一步弹出undefined就是有问题了
      

  16.   

    TO  wxlada(绿茶) 我前面二是弹出undefined,
    alert(document.all("divWSBehavior").ProductPrice); 弹出的也是undefinded. to jsijy(小卢)我有webservice.htc 这个文件
      

  17.   

    能把你的代码发一份过来吗?[email protected]
      

  18.   

    不对,发不出来。这里下载好了。http://gao.66ip.com/a.rar