web service 在我这台服务器上提供了一种方法 但是如何从远程调用这种方法呢?
例如 [WebMethod]
        public int add(int a,int b)
        {
            return a + b;
        }
提供了两数相加的方法 然后我将这种方法发布到IIS上 远程怎样调用这种方法?就是说怎样传递a,和b,然后再接受返回的结果。
还有是利用下面这段代码吗?
POST /math/math.asmx HTTP/1.1 
Host: localhost 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "" 
<soap:Envelope  
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 

<soap:Body> 
<Add xmlns="http://example.org/math"> 
<x>33</x> 
<y>66</y> 
</Add> 
</soap:Body> 
</soap:Envelope> 

解决方案 »

  1.   

    添加web引用,和网站使用web service是一样的。
    http://www.taian-seo.com/it/csharp_webserver.html
      

  2.   

    部署到IIS上后,知道这个WSDL的地址,再在使用方,通过添加Web引用的方式,起个名字(比如叫MyService)添加进来。VS会帮你自动生成本地的代理类。你在程序里直接就像使用别的程序集一样使用它。//Service1是定义的WebService类名而定
    MyService.Service1 webSvc = new MyService.Service1();int result = webSvc.Add(1, 2);MessageBox.Show(result.ToString());
      

  3.   

    也可用ajax
    $.ajax({
       url:"xx/add",
       data:{a:1,b:2},
       dataType:"json",
       success:function(result){
            alert(result.d);
       }
    })