import jakarta.jws.WebMethod; import jakarta.jws.WebService; @WebService public class MyWebService { @WebMethod public String sayHello(String name) { return "Hello, " + name + "!"; } } import jakarta.xml.ws.Endpoint; import jakarta.xml.ws.EndpointReference; import jakarta.xml.ws.spi.WebServiceFeatureAnnotation; import jakarta.xml.ws.spi.WebServiceFeatureAnnotation.Accessor; public class MetadataGenerator { public static void main(String[] args) { String wsdlURL = "http://localhost:8080/MyWebService?wsdl"; String outputFileName = "MyWebServiceMetadata.xml"; Endpoint endpoint = Endpoint.create(new MyWebService()); endpoint.publish(wsdlURL); EndpointReference endpointRef = endpoint.getEndpointReference(); MetadataReader metadataReader = MetadataFactory.createMetadataReader(endpointRef, null); Metadata metadata = metadataReader.getMetadata(); try { metadata.writeTo(new FileOutputStream(outputFileName)); } catch (IOException e) { } endpoint.stop(); } }


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