我需要使用我正在编写的 Java 程序来使用 SOAP Web 服务。我的服务器上有一个基本的测试 .NET 服务,位于 .asmx 文件中。我在谷歌上找到了一堆复杂的例子,但有人能为我提供一个简短的解释吗?这将不胜感激。谢谢!
这是我的 .asmx 文件。
<%@ WebService Language="C#" Class="Example1" %>
using System.Web.Services;
[WebService(Namespace="urn:Example1")]
public class Example1 {
[ WebMethod ]
public string sayHello(string name) {
return "Hello " + name;
}
}
也许我应该采取不同的方式?再次感谢。
最佳答案
您可以使用 JDK 附带的名为 wsimport
的工具来解析 WSDL 文件并生成 Java 类。
wsimport http://path/to/your?wsdl -d /desired/output/folder
然后您可以像这样使用生成的类:
Example1Endpoint example1 = new Example1Service().getExample1Port();
System.out.println(example1.sayHello("tkcsam"));
关于c# - 如何使用 Java 使用 SOAP Web 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7081972/