这是一个用Java调用C#版WebService接口的例子:


C#接口:

Java代码 用Java调用WebService _Java 用Java调用WebService _Java_02
  1. <SPAN style="FONT-SIZE: 11px">
  2. using System;
  3. using System.Web;
  4. using System.Web.Services;
  5. using System.Web.Services.Protocols;
  6. using System.Web.Services.Description;
  7.  
  8.  
  9. [WebService(Namespace = "http://www.tangs.com/")]
  10. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  11. public class Service : System.Web.Services.WebService
  12. {
  13. public Service () ...{
  14.  
  15. //如果使用设计的组件,请取消注释以下行
  16. //InitializeComponent();
  17. }
  18.  
  19. [SoapRpcMethod(Action = "http://www.tangs.com/Add", RequestNamespace = "http://www.tangs.com/T", ResponseNamespace = "http://www.tangs.com/T", Use = SoapBindingUse.Literal)]
  20. [WebMethod]
  21. public int Add(int a, int b)
  22. ...{
  23. return a + b;
  24. }
  25.  
  26. [SoapRpcMethod(Action = "http://www.tangs.com/Hello", RequestNamespace = "http://www.tangs.com/T", ResponseNamespace = "http://www.tangs.com/T", Use = SoapBindingUse.Literal)]
  27. [WebMethod]
  28. public String HelloWorld()
  29. ...{
  30. return "Hello, world!";
  31. }
  32.  
  33. }
  34. ...</SPAN>