.net代码如下,
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class SysService : System.Web.Services.WebService
{
public SysService()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
http://localhost:1937/Web/SysService.asmx?wsdl
用eclipse工具生成客户端代码:
选中工程--》新建-》其他-》web services 客户端 ,把http://localhost:1937/Web/SysService.asmx?wsdl 地址输入进去
下一步 下一步 最后完成
就会生成java的客户端代码
调用:
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
public class test {
/**
* @param args
* @throws ServiceException
* @throws RemoteException
*/
public static void main(String[] args) throws ServiceException, RemoteException {
SysServiceLocator locator;
SysServiceSoap locatorService;
locator = new SysServiceLocator();
locatorService = locator.getSysServiceSoap();
String output = locatorService.helloWorld();
System.out.println("-------------"+output);
}
}
最后输出:警告: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
-------------Hello World