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>
例如 [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>
http://www.taian-seo.com/it/csharp_webserver.html
MyService.Service1 webSvc = new MyService.Service1();int result = webSvc.Add(1, 2);MessageBox.Show(result.ToString());
$.ajax({
url:"xx/add",
data:{a:1,b:2},
dataType:"json",
success:function(result){
alert(result.d);
}
})