To make a web service call in Java using a WSDL (Web Services Description Language) file, you can use the javax.xml.ws
package, which provides the necessary classes and methods to invoke a web service.
Here is an example of how to make a web service call in Java using a WSDL file:
import javax.xml.ws.Service; import java.net.URL; public class Main { public static void main(String[] args) throws Exception { // Create a URL for the WSDL file URL url = new URL("http://www.example.com/service?wsdl"); // Create a Service object from the WSDL file Service service = Service.create(url, new QName("http://www.example.com/", "MyService")); // Get a proxy for the web service MyServiceInterface myService = service.getPort(MyServiceInterface.class); // Invoke the web service method String result = myService.sayHello("John"); // Print the result System.out.println(result); } }
In this example, the Service
class is used to create a Service
object from the WSDL file, and the getPort()
method is used to get a proxy for the web service. The web service method is then invoked using the proxy, and the result is printed to the console.
Note that you will need to have the appropriate WSDL file and web service interface available, as well as any required dependencies in your classpath. You may also need to adjust the code to match the specific structure and requirements of your web service.
For more information on web service calls in Java and the javax.xml.ws
package, you can refer to the Java documentation or other online resources.