<dependency> <groupId>wsdl4j</groupId> <artifactId>wsdl4j</artifactId> <version>1.6.3</version> </dependency> import javax.wsdl.*; import javax.wsdl.factory.*; import javax.wsdl.xml.*; import java.io.*; public class WSDLGenerator { public static void main(String[] args) throws Exception { Definition definition = DefinitionFactory.newInstance().newDefinition(); String targetNamespace = "http://example.com/MyService"; definition.setTargetNamespace(targetNamespace); PortType portType = definition.createPortType(); portType.setQName(new QName(targetNamespace, "MyServicePortType")); Operation operation = portType.createOperation(); operation.setName("HelloWorld"); Message inputMessage = definition.createMessage(); inputMessage.setQName(new QName(targetNamespace, "HelloWorldInput")); operation.setInput(inputMessage); Message outputMessage = definition.createMessage(); outputMessage.setQName(new QName(targetNamespace, "HelloWorldOutput")); operation.setOutput(outputMessage); definition.addPortType(portType); WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter(); writer.writeWSDL(definition, new FileOutputStream("MyService.wsdl")); } } import javax.jws.*; @WebService(targetNamespace="http://example.com/MyService", serviceName="MyService") public class MyServiceImpl implements MyServicePortType { @WebMethod(operationName="HelloWorld") public String helloWorld(String input) { return "Hello, " + input + "!"; } }


上一篇:
下一篇:
切换中文