How to Call a WCF service in java

Viewed 884

I am new to Java and I need to call a WCF. Is there any way in Java that I do not need to consume it and can directly hit the url to get response?

3 Answers

For Java client application, I think you can generate the proxy class from Eclipse and invoke the call to WCF service.

The general steps are as follows:

  1. Prepare the WCF service and run the service.

  2. Create the Java client application in Eclipse IDE, and name the project, like WCFClientApp in this case.

You can follow this blog for better practical understanding https://www.codeproject.com/Articles/777036/Consuming-WCF-Service-in-Java-Client

You can make a direct call using HttpURLConnection in the Java.Net library

URL url = new URL("https://{ApiEndpoint}/v2/EmailMarketing.svc/SendEmail");
HttpURLConnection http = (HttpURLConnection)url.openConnection();
http.setRequestMethod("POST");
http.setDoOutput(true);
http.setRequestProperty("Content-Type", "application/json");
http.setRequestProperty("Accept", "application/json");

String data = "{\"Id\": 78912, \"Quantity\": 1, \"Price\": 19.00}";

byte[] out = data.getBytes(StandardCharsets.UTF_8);

OutputStream stream = http.getOutputStream();
stream.write(out);

System.out.println(http.getResponseCode() + " " + 
http.getResponseMessage());
http.disconnect();
Related